Skip to content
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

Error : Cannot get final name for export 'getRuntime' of ./node_modules/openai/_shims/auto/runtime-node.mjs #789

Closed
1 task done
jiveshkalra opened this issue Apr 20, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@jiveshkalra
Copy link

jiveshkalra commented Apr 20, 2024

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 am trying to use Langchain + NextJs for hosting my chatbot , and it works fine in the development server ,
But when I try to compile my code to host on the vercel server, I am getting this error

Failed to compile.

./node_modules/@langchain/openai/index.js + 66 modules
Cannot get final name for export 'getRuntime' of ./node_modules/openai/_shims/auto/runtime-node.mjs

To Reproduce

  1. Make a Next Js project
  2. Add openai and langchain to it
  3. make a basic chain.
  4. run npm run build

Code snippets

    const chain = ConversationalRetrievalQAChain.fromLLM(
      model,
      vectorStore.asRetriever()
    );
    // Format the messages
    const formattedChatPrompt = await chatPrompt.formatMessages({
      text: question,
    });

    const res = await chain.invoke({
      question,
      chat_history: formattedChatPrompt,
    });

OS

Windows

Node version

Node v20.9.0

Library version

OpenAI v4.38.2

@jiveshkalra jiveshkalra added the bug Something isn't working label Apr 20, 2024
@rattrayalex
Copy link
Collaborator

How are you compiling your project? eg, are you using turborepo or webpack?

@guru-parama
Copy link

I'm also facing a similar kind of issue in Ubuntu

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './_shims/auto/runtime' is not defined by "exports" in /home/ubuntu/backend/node_modules/openai/package.json

Node Version - v18.12.1
Openai Version - v4.38.3

@jiveshkalra
Copy link
Author

jiveshkalra commented Apr 23, 2024

are you using nextjs or webapck?

I got it to work in webpack/nextjs by changing the webpack/next config

@demenskyi
Copy link

demenskyi commented Apr 23, 2024

are you using nextjs or webapck?

I got it to work in webpack/nextjs by changing the webpack/next config

Hey @jiveshkalra how did you do that? I'm facing the same issue. I'm using next.js with monorepo.

@demenskyi
Copy link

Never mind @jiveshkalra.

For those looking for an answer try the following:

// next.config.js

/** @type {import('next').NextConfig} */
const nextConfig = {
  experimental: {
    serverComponentsExternalPackages: ["<PACKAGE_NAME>"],
  },
};

module.exports = nextConfig;

@jiveshkalra
Copy link
Author

for me it was an issue with webpack not exporting the package files properly
I fixed it by setting this in my config

// next.config.js
/** @type {import('next').NextConfig} */
const nextConfig = { 
  webpack: (config ) => { 
    config.externals = [...config.externals, "hnswlib-node","closevector-hnswlib-node" ,"openai"]; 
    return config;
  },
};

export default nextConfig;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants