-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OpenAI import fails in Vercel deployment Cannot find module '/var/task/node_modules/openai/_shims/agent-node.mjs'
#2558
Comments
🤖 Hello, The error you're encountering is likely due to the fact that Vercel's serverless functions do not fully support ESM (ECMAScript Modules) yet. The To resolve this issue, you can try to bundle your serverless function with a tool like Webpack or esbuild, which will convert ESM imports to CommonJS, which is supported by Vercel. Here is an example of how you can use esbuild to bundle your serverless function:
npm install --save-dev esbuild
"scripts": {
"build": "esbuild src/pages/api/hello-serverless.ts --bundle --platform=node --target=node14 --outfile=dist/hello-serverless.js"
}
npm run build
{
"functions": {
"api/hello-serverless.js": {
"runtime": "nodejs14.x",
"includeFiles": "dist/**"
}
}
}
vercel --prod This will bundle your serverless function into a single file that uses CommonJS, which should resolve the error. As for LangChain specific configurations or requirements for deployment on serverless platforms like Vercel, I couldn't find any specific information in the repository. However, the general rule of thumb is to ensure that all dependencies are correctly installed and that the environment supports the features used by LangChain, such as ESM. I hope this helps! Let me know if you have any other questions. SourcesThis response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot. |
Hey @raphaelmsr, we recently upgraded to OpenAI's v4 SDK under the hood - does downgrading to 0.0.140 fix it? https://github.com/hwchase17/langchainjs/releases/tag/0.0.140 Also, in the short term, things should work in Next.js apps WITH the app directory if that's an option for you: https://github.com/langchain-ai/langchain-nextjs-template/blob/main/package.json |
Hey @jacoblee93 ! thanks for the quick reply; will try downgrading ! EDIT : IT WORKED 😱 Can't believe I spent the day on this haha Thanks a million for such a quick reply
|
Glad to hear it! Sorry you're encountering this.
|
Opened an issue on OpenAI as I was able to repro with their SDK alone. Will leave this open until it's patched there. Thanks again for the report! |
Thanks for following up and opening tickets on the OpenAI repo! Will follow so I can finally update 😊 |
@raphaelmsr I downgraded the OpenAI version in 0.0.146 so you should be able to upgrade to that. Closing this for now but reopen if you encounter trouble again. |
Thanks for the update ! |
Using NextJS 13 without appDir, I just installed LangchainJS for use in my tRPC back-end
In local everything works like a charm.
After deploying on Vercel as a Serverless function, I have this strange error
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/var/task/node_modules/openai/_shims/agent-node.mjs' imported from /var/task/node_modules/openai/core.mjs at new NodeError (node:internal/errors:405:5) at finalizeResolution (node:internal/modules/esm/resolve:329:11) at moduleResolve (node:internal/modules/esm/resolve:992:10) at moduleResolveWithNodePath (node:internal/modules/esm/resolve:936:12) at defaultResolve (node:internal/modules/esm/resolve:1178:79) at nextResolve (node:internal/modules/esm/loader:163:28) at ESMLoader.resolve (node:internal/modules/esm/loader:835:30) at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18) at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:77:40) at link (node:internal/modules/esm/module_job:76:36) { code: 'ERR_MODULE_NOT_FOUND' }
I couldn't find any issue mentioning this error anywhere, hope this is the right place to open an issue !
Thanks in advance
The text was updated successfully, but these errors were encountered: