langchainjs: Dependency conflicts

I’m running langchain in a project that already contains a mongodb. When I install langchain in this project, I’m getting depency conflicts:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: langchain@0.0.185
npm ERR! Found: mongodb@6.2.0
npm ERR! node_modules/mongodb
npm ERR!   mongodb@"^6.2.0" from the root project
npm ERR!   peer mongodb@">= 5.1.0 < 7" from connect-mongo@5.1.0
npm ERR!   node_modules/connect-mongo
npm ERR!     connect-mongo@"^5.1.0" from the root project
npm ERR!   1 more (mongoose)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peerOptional mongodb@"^5.2.0" from langchain@0.0.185
npm ERR! node_modules/langchain
npm ERR!   langchain@"^0.0.185" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: mongodb@5.9.1
npm ERR! node_modules/mongodb
npm ERR!   peerOptional mongodb@"^5.2.0" from langchain@0.0.185
npm ERR!   node_modules/langchain
npm ERR!     langchain@"^0.0.185" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

Looking at this, it seems it’s an optional dependency. As far as I know, I don’t use the mongodb functionalities of lanchain itself.

As I understand, I can omit the optional dependencies by running npm install --omit=optional. This unfortunately gives the same error. I’m aware of npm install --legacy-peer-deps, but I’d rather not do this as the rest of my package dependencies work fine and I don’t want to break that.

Ideally langchain would be a bit less strict here. Or maybe I’m missing something. Any ideas?

About this issue

  • Original URL
  • State: open
  • Created 8 months ago
  • Comments: 15

Most upvoted comments

@jacoblee93 I understand your point of view, I also struggled with peer deps before. But as it stands langchain is the only package that prevents me from doing a normal npm install. I can’t be the only one that want to include langchain in an existing project.

But whenever your project includes a newer package than the optional dependency that langchain defines in its peer deps, regardless of whether you use this optional dependency with langchain, this prevents you from doing a normal npm install.

Maybe make the optional peer dependencies into proper, separate optional plugin packages?

🤖

I understand your concern about the dependency conflict between langchain and mongodb. This seems to be a common issue with npm when multiple packages depend on different versions of the same package.

Based on the similar issues I found in the langchainjs repository, one way to resolve this is by using the npm-force-resolutions package. This package allows you to force the resolution of specific dependencies to a specific version. Here’s how you can do it:

  1. Install npm-force-resolutions by running npm install npm-force-resolutions.

  2. In your package.json, add a resolutions field specifying the version of mongodb that you want to use. For example:

"resolutions": {
  "mongodb": "3.6.6"
}
  1. Modify your scripts field to include a preinstall script that runs npm-force-resolutions:
"scripts": {
  "preinstall": "npx npm-force-resolutions"
}
  1. Run npm install.

This will force npm to resolve mongodb to the specified version, resolving the conflict with langchain.

Please note that this solution assumes that the version of mongodb specified in the resolutions field is compatible with all your dependencies. If this is not the case, you may need to find a version that is compatible with all your dependencies, or consider using a different solution.

Unfortunately, I wasn’t able to find the exact version of mongodb that langchainjs is compatible with in the repository. You might need to experiment with different versions to find one that works.

I hope this helps! If you have any other questions or need further clarification, feel free to ask.

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 because of npm’s stricter peer dependency validation 😦 we suggest using yarn or pnpm but will be working to address this more in a future 0.2.0 (which will be breaking).

We have actively started doing the above - we will be factoring more and more integrations into their own packages/community and the current plan is to fully remove the community dep in the next minor release.

Thanks for the work! it works perfectly fine with the new Pinecone from the update you just pushed! 😃

Ran into the same issue since version 0.0.183 but with @vercel/kv:

npm ERR! @vercel/kv@“^1.0.0” from the root project npm ERR! npm ERR! Could not resolve dependency: npm ERR! peerOptional @vercel/kv@“^0.2.3” from langchain@0.0.185