Next.js Discord

Discord Forum

Issue Deploying to Vercel using LangChain JS & NEXT JS 14

Answered
Border Terrier posted this in #help-forum
Open in Discord
Border TerrierOP
Hello, i encountered this error while trying to deploy a test to vercel...

next build
â–² Next.js 14.0.2
Creating an optimized production build ...
Failed to compile.
./node_modules/langchain/dist/chains/question_answering/refine_prompts.js + 4 modules
Cannot get final name for export 'PromptTemplate' of ./node_modules/langchain/dist/prompts/index.js
Build failed because of webpack errors
Error: Command "npm run build" exited with 1


locally works perfect :thinkies:
Answered by Border Terrier
View full answer

39 Replies

@Savannah Did you find a fix?
Border TerrierOP
not yet, i only found people who said something about maybe being related to TS types error... but nothing really with evidence of the error
Savannah
Meh i cant make it work and am stuck
Satin Angora
When you say it works locally does it also build locally ?
Try going to to your next.config and adding this
 module.exports =  {
    ...otherstuff
    future : {
    webpack5: true,
}  
},
@Satin Angora Try going to to your next.config and adding this
Savannah
that is already enabled by default right?
still the same issue here
Satin Angora
Ok so when I looked online I saw this issue

https://github.com/langchain-ai/langchainjs/issues/2335

They've suggested to add the following :

module.exports = {
  swcMinify: false,
  webpack5: {
    module: {
      rules: [
        {
          test: /node_modules\/langchain/,
          resolve: {
            fullySpecified: false,
          },
        },
      ],
    },
  },
};
@Savannah that is already enabled by default right?
Satin Angora
You're 100% right this is actually enabled by default I just found it as a solution for whatever reason on a github form but with the current version it should just be a default already
Apparently this issue steps from the minification process..

Another suggestion was to remove the following

    serverActions: true,


However, this may have some implications if you're currently using serverActions of course
Savannah
Im using Server Actions
Satin Angora
In that case try that first suggestion but it seems to be a common issue with nextJS 14 and server actions now that I am reading into it which is a shame because apparently with this release its meant to be stable hopefully they come up with a fix for it soon.
Satin Angora
Yeah its a huge blocker and tbh frustrating that this is even an issue as its been around since next 13 apparently in the experimental version
But surely there has to be a work around I am looking through the forums now to learn more about it.. And to confirm it builds locally? when you run the build command
Savannah
npm run dev is fine but npm run build gives this error
Savannah
So annoying
Border TerrierOP
haven't found a fix for this, been trying a lot of suggestions but nothing yet
Border TerrierOP
@Savannah are you using the VERCEL AI SDK?
Savannah
No
Just Langchain
Its annoying
And because op Server Actions
Border TerrierOP
I FOUND A SOLUTION @Savannah
Border TerrierOP
Answer
Border TerrierOP
just import the PropmtTemplate anywhere and make sure you call it
Savannah
Haha omggg
Really
I’ll try in a bit!
Savannah
Works!
hahah nice one pfff
@Savannah Works!
Border TerrierOP
Glad to help

God damn... a whole week struggling with this error