langchainjs
langchainjs copied to clipboard
Cannot get final name for export 'PromptTemplate' of ./node_modules/langchain/dist/prompts/index.js
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.
🤖
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.
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;
},
};
Bug is coming because of this part:
experimental: {
serverActions: true,
},
When serverActions
is removed, it's compiling fine.
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.
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! 😃
I also have this issue. Does anybody have a fix already?
Also having this issue
I have this issue but for a different lib. Upvoting here so it gains traction
Not the solution you want but...
This works,
Thanks @KarloAldrete
Not the solution you want but...
![]()
Just tried it out! Working!
My eyes hurt, but it really works.
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!
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
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.
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