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

Next.js build failing after version 14.2 with ConversationChain #5235

Open
5 tasks done
TheOrcDev opened this issue Apr 27, 2024 · 5 comments
Open
5 tasks done

Next.js build failing after version 14.2 with ConversationChain #5235

TheOrcDev opened this issue Apr 27, 2024 · 5 comments
Labels
auto:bug Related to a bug, vulnerability, unexpected error with an existing feature

Comments

@TheOrcDev
Copy link

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain.js documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain.js rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

The followind code:

import { ChatOpenAI } from "@langchain/openai";
import { BufferMemory } from "langchain/memory";
import { ConversationChain } from "langchain/chains";

const model = new ChatOpenAI({
  modelName: process.env.GPT_MODEL,
  openAIApiKey: process.env.GPT_API_KEY,
  temperature: parseFloat(process.env.GPT_TEMPERATURE ?? "0.8"),
  maxTokens: parseInt(process.env.GPT_MAX_TOKENS ?? "1048"),
});

const memory = new BufferMemory();

const chain = new ConversationChain({
  llm: model,
  memory,
  verbose: true,
});

Error Message and Stack Trace (if applicable)

Error message on build only:

./node_modules/.pnpm/langchain@0.1.36/node_modules/langchain/dist/chains/analyze_documents_chain.js + 5 modules
Cannot get final name for export 'getEncoding' of ./node_modules/.pnpm/@langchain+core@0.1.61_openai@4.38.5/node_modules/@langchain/core/utils/tiktoken.js

./node_modules/.pnpm/langchain@0.1.36/node_modules/langchain/dist/memory/entity_memory.js + 3 modules
Cannot get final name for export 'Serializable' of ./node_modules/.pnpm/@langchain+core@0.1.61_openai@4.38.5/node_modules/@langchain/core/load/serializable.js

./node_modules/.pnpm/langchain@0.1.36/node_modules/langchain/dist/output_parsers/openai_functions.js + 1 modules
Cannot get final name for export 'compare' of ./node_modules/.pnpm/@langchain+core@0.1.61_openai@4.38.5/node_modules/@langchain/core/utils/json_patch.js

Description

Everything is working locally, only build is failing, so deployment is not possible.

System Info

"langchain": "^0.1.36",
"next": "^14.2.3",
Copy link

dosubot bot commented Apr 27, 2024

The error messages you're encountering during the Next.js build process seem to stem from issues related to ES module imports and possibly the handling of dependencies by Next.js. Here's a more focused approach to troubleshoot and potentially resolve these issues:

  1. Ensure Compatibility with ES Modules: Verify that your project setup and Next.js version are fully compatible with ES modules, as LangChain.js is likely utilizing them. Next.js generally supports ES modules out of the box, but custom configurations might interfere with this.

  2. Check Node Version: Make sure you're using Node.js version 18 or higher, as compatibility issues might arise with older versions.

  3. Review Import Paths: Align your import statements with the exports field in LangChain.js's package.json. Incorrect import paths can lead to the errors you're seeing. For instance, ensure you're using the correct path for importing Serializable and other modules.

  4. Install Necessary Dependencies: Go through the dependencies and peerDependencies listed in LangChain.js's package.json. While peerDependencies are optional, they might be required for your specific use case, especially for integrations with external services.

  5. Adjust TypeScript Configuration: If your project uses TypeScript, ensure your tsconfig.json is properly configured to handle ES modules and the library's type definitions.

  6. Examine Build Process: Consider if your build process is aligned with handling libraries structured as ES modules. The error might be related to how Next.js is processing these modules during the build.

  7. Install Relevant Peer Dependencies: Some functionalities might require installing peer dependencies listed in LangChain.js. Check if adding these dependencies resolves the issue.

If after trying these steps you're still facing build issues, it might be helpful to create a minimal reproduction case to isolate the problem further. Additionally, reviewing similar issues in the LangChain.js repository or related discussions might provide more context or solutions specific to your problem.

Details

Sources


About Dosu
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.

To continue the conversation, mention @dosu.

@dosubot dosubot bot added the auto:bug Related to a bug, vulnerability, unexpected error with an existing feature label Apr 27, 2024
@hnykda
Copy link

hnykda commented Apr 29, 2024

It's very similar to what I saw in the past with #2335 .

We have production building fine, but now due to totally unrelated changes (really just some FE stuff and some DB comm) on a different feature branch, the build fails. The bot stuff are not helpful.

For us, it's the:

Failed to compile.

./node_modules/langchain/dist/output_parsers/openai_functions.js + 1 modules
Cannot get final name for export 'compare' of ./node_modules/@langchain/core/utils/json_patch.js

Anyway, I tried a similar workaround as in that other PR, adding an import to somewhere in our codebase, and it works 🤦 :

// hacks.ts, import somewhere in your codebase
import { compare } from '@langchain/core/utils/json_patch';
const DoNotRemove = compare;

@TheOrcDev
Copy link
Author

It's very similar to what I saw in the past with #2335 .

We have production building fine, but now due to totally unrelated changes (really just some FE stuff and some DB comm) on a different feature branch, the build fails. The bot stuff are not helpful.

For us, it's the:

Failed to compile.

./node_modules/langchain/dist/output_parsers/openai_functions.js + 1 modules
Cannot get final name for export 'compare' of ./node_modules/@langchain/core/utils/json_patch.js

Anyway, I tried a similar fix as in that other PR, adding an import to somewhere in our codebase, and it works 🤦 :

// hacks.ts, import somewhere in your codebase
import { compare } from '@langchain/core/utils/json_patch';
const DoNotRemove = compare;

This weird eye hurting fix left me with two build problems :D

./node_modules/.pnpm/langchain@0.1.36/node_modules/langchain/dist/chains/analyze_documents_chain.js + 5 modules
Cannot get final name for export 'getEncoding' of ./node_modules/.pnpm/@langchain+core@0.1.61_openai@4.38.5/node_modules/@langchain/core/utils/tiktoken.js

./node_modules/.pnpm/langchain@0.1.36/node_modules/langchain/dist/memory/entity_memory.js + 3 modules
Cannot get final name for export 'Serializable' of ./node_modules/.pnpm/@langchain+core@0.1.61_openai@4.38.5/node_modules/@langchain/core/load/serializable.js

@hnykda
Copy link

hnykda commented Apr 29, 2024

You just have to hurt yourself a bit more by figuring out where from you could import those two getEncoding and Serializable and do the same shenanigas

@TheOrcDev
Copy link
Author

You just have to hurt yourself a bit more by figuring out where from you could import those two getEncoding and Serializable and do the same shenanigas

Here is the fix, prepare yourself.

import { compare } from "@langchain/core/utils/json_patch";
import { Serializable } from "@langchain/core/load/serializable";
import { getEncoding } from "@langchain/core/utils/tiktoken";
import { RecursiveCharacterTextSplitter } from "langchain/text_splitter";

const DoNotRemoveCompare = compare;
const DoNotRemovegetEncoding = getEncoding;
const DoNotRemoveSerializable = Serializable;
const DoNotRemoveRecursiveCharacterTextSplitter = RecursiveCharacterTextSplitter;

That's all I can do before the actual fix. Thanks @hnykda !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:bug Related to a bug, vulnerability, unexpected error with an existing feature
Projects
None yet
Development

No branches or pull requests

2 participants