langchainjs icon indicating copy to clipboard operation
langchainjs copied to clipboard

Cannot get final name for export 'PromptTemplate' of ./node_modules/langchain/dist/prompts/index.js

Open TheOrcDev opened this issue 1 year ago • 15 comments

When building a project in Next.js version 13.4, getting this error:

UPDATE: Next.js 14.0 same error

Cannot get final name for export 'PromptTemplate' of ./node_modules/langchain/dist/prompts/index.js

It's breaking the build, and not able to deploy it to Vercel.

TheOrcDev avatar Aug 19 '23 21:08 TheOrcDev

🤖

Hello,

The error you're encountering is likely due to the new optimizations introduced in Next.js version 12 and onwards, which include a more aggressive tree-shaking and minification process. This can sometimes cause issues with certain types of exports from third-party libraries, such as LangChain in your case.

To resolve this issue, you can disable the new optimizations by adding the following configuration to your next.config.js file:

module.exports = {
  swcMinify: false,
  webpack5: {
    module: {
      rules: [
        {
          test: /node_modules\/langchain/,
          resolve: {
            fullySpecified: false,
          },
        },
      ],
    },
  },
};

This configuration disables the SWC minifier and tells webpack to treat imports from the langchain module as not fully specified, which can help resolve issues with certain types of exports. After adding this configuration, try building your project again and deploying it on Vercel.

In the context shared, it's also important to note that you're using a workspace version of LangChain. If the issue persists after making the above changes, you might want to consider using a stable release version of LangChain instead of the workspace version. You can do this by updating the "langchain" line in your package.json file to the specific version number you want to use.

Please let me know if this resolves your issue or if you need further assistance.

Sources


This 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.

dosubot[bot] avatar Aug 19 '23 21:08 dosubot[bot]

It's not solving it, also tried this one:

const nextConfig = {
  experimental: {
    serverActions: true,
  },
  webpack: (config, { isServer }) => {
    if (!isServer) {
      config.resolve.fullySpecified = false;
    }

    config.module.rules.push({
      test: /node_modules\/langchain/,
      resolve: {
        fullySpecified: false,
      },
    });

    return config;
  },
};

TheOrcDev avatar Aug 27 '23 20:08 TheOrcDev

Bug is coming because of this part:

experimental: {
    serverActions: true,
},

When serverActions is removed, it's compiling fine.

TheOrcDev avatar Aug 27 '23 20:08 TheOrcDev

It happened to me on NextJS 14.1 where the server actions should be stable... In my case, it happened by importing a type for something totally unrelated to langchain. I gave up on trying to figure what it was, gave up on the said type, it's dark magic.

hnykda avatar Nov 08 '23 14:11 hnykda

It happened to me on NextJS 14.1 where the server actions should be stable... It was caused by importing a type for something totally unrelated to langchain. I gave up on trying to figure what it was, it's dark magic.

Haven't tested it yet, I thought new Next.js 14.0 is going to fix it. Better luck next time! 😃

TheOrcDev avatar Nov 08 '23 14:11 TheOrcDev

I also have this issue. Does anybody have a fix already?

guidsen avatar Nov 13 '23 08:11 guidsen

Also having this issue

connorblack avatar Nov 15 '23 21:11 connorblack

I have this issue but for a different lib. Upvoting here so it gains traction

ochmanski avatar Nov 15 '23 21:11 ochmanski

Not the solution you want but... langchain image

KarloAldrete avatar Nov 16 '23 23:11 KarloAldrete

This works, image Thanks @KarloAldrete

BhaveshKumarSharma avatar Dec 01 '23 08:12 BhaveshKumarSharma

Not the solution you want but... langchain image

Just tried it out! Working!

TheOrcDev avatar Dec 01 '23 23:12 TheOrcDev

My eyes hurt, but it really works.

hnykda avatar Jan 30 '24 20:01 hnykda

Hi, @TheOrcDev

I'm helping the langchainjs team manage their backlog and am marking this issue as stale. From what I understand, you reported a build error in Next.js versions 13.4 and 14.0 related to exporting 'PromptTemplate' from a file in the langchain module, causing deployment issues to Vercel. You and other users attempted various solutions, and a potential workaround involving images was suggested and confirmed to work by other contributors.

Could you please confirm if this issue is still relevant to the latest version of the langchainjs repository? If it is, please let the langchainjs team know by commenting on the issue. Otherwise, feel free to close the issue yourself, or it will be automatically closed in 7 days. Thank you!

dosubot[bot] avatar Apr 30 '24 16:04 dosubot[bot]

Hi. It's probably not an issue with this instance, but something fishy is still going on as https://github.com/langchain-ai/langchainjs/issues/5235 is almost exactly the same (on latest next 14.2.1 and latest langchain). You might want to close some of these and have just one issue tracking this recurring thing

hnykda avatar Apr 30 '24 16:04 hnykda

Hi! Like @hnykda said it's still happening on #5235

That's the same bug happening on latest Next.js version. We can leave one issue on GitHub until it's fixed.

TheOrcDev avatar Apr 30 '24 19:04 TheOrcDev

expercing same issue when trying to deploy next js langachin app .Cannot get final name for export 'BaseMemory' of ./node_modules/@langchain/core/memory.js. im trying the solution above but i experience same issue

RespectMashego avatar May 25 '24 00:05 RespectMashego