openai-node: Module not found error on v4.5.0

Confirm this is a Node library issue and not an underlying OpenAI API issue

  • This is an issue with the Node library

Describe the bug

I was following the tutorial to integrate nextjs with openai and noticed that the latest release (v4.5.0) is throwing a module not found error.

./node_modules/.pnpm/openai@4.5.0/node_modules/openai/core.mjs:32:0
Module not found: Can't resolve 'openai/_shims/agent.mjs'

https://nextjs.org/docs/messages/module-not-found

Import trace for requested module:
./node_modules/.pnpm/openai@4.5.0/node_modules/openai/index.mjs
./pages/api/completion.ts
./node_modules/.pnpm/next@13.4.3_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/build/webpack/loaders/next-edge-function-loader.js?absolutePagePath=%2Fhome%2Fgxara%2FPessoal%2FProjetos%2Fknowledge-tree%2Fpages%2Fapi%2Fcompletion.ts&page=%2Fapi%2Fcompletion&rootDir=%2Fhome%2Fgxara%2FPessoal%2FProjetos%2Fknowledge-tree&preferredRegion=!

Maybe this is something related to this change:

image

Important: I did a downgrade to version v4.4.0 and everything worked as expected.

To Reproduce

  1. Install release v4.5.0
  2. import OpenAI from "openai";

Code snippets

No response

OS

Debian

Node version

Node v18.17.1

Library version

openai v4.5.0

About this issue

  • Original URL
  • State: closed
  • Created 10 months ago
  • Reactions: 5
  • Comments: 18

Most upvoted comments

Thanks, the new release addressed my problem @rattrayalex

Awesome, thanks @rattrayalex !

Sorry about this! We’re working on a fix.

@lautapercuspain This is a problem in Node.js environments (so the Vercel Serverless offering running on Node). I haven’t noticed any issues with it running on our Edge Functions. The downgrade fixed it for us though for now 👍