langchainjs icon indicating copy to clipboard operation
langchainjs copied to clipboard

Dependency conflicts

Open Monokai opened this issue 1 year ago • 18 comments

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: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/mongodb
npm ERR!   mongodb@"^6.2.0" from the root project
npm ERR!   peer mongodb@">= 5.1.0 < 7" from [email protected]
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 [email protected]
npm ERR! node_modules/langchain
npm ERR!   langchain@"^0.0.185" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: [email protected]
npm ERR! node_modules/mongodb
npm ERR!   peerOptional mongodb@"^5.2.0" from [email protected]
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?

Monokai avatar Nov 10 '23 07:11 Monokai

🤖

Hello @Monokai,

Nice to meet you! I'm here to assist with your issue while we wait for a human maintainer to step in. As a bot, I'm equipped to help you troubleshoot bugs, answer questions, and guide you in contributing to the repository. Rest assured, I'm currently examining the dependency conflict issue you've raised and will get back to you with a comprehensive response shortly.

dosubot[bot] avatar Nov 10 '23 07:11 dosubot[bot]

🤖

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.

dosubot[bot] avatar Nov 10 '23 07:11 dosubot[bot]

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 [email protected]

ElectricCodeGuy avatar Nov 10 '23 09:11 ElectricCodeGuy

This behavior for unused peer deps is a bit silly by npm and can be safely ignored with your command above. yarn and pnpm both don't have this problem.

We can set * or >= as a dep but that has caused problems for us in the past because it can result in peer deps updating and creating version conflicts with other peer deps. It still might be the best solution for now if this is becoming more common...

jacoblee93 avatar Nov 13 '23 08:11 jacoblee93

@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?

Monokai avatar Nov 13 '23 08:11 Monokai

Yes, long term something like that is going to be the best solution, but a significant amount of work. Maybe using >= is a good compromise in the short run

jacoblee93 avatar Nov 13 '23 15:11 jacoblee93

same issue here.

Fixed by using overrides inside package.json for NPM

    "overrides": {
        "mongodb": "6.2.0"
    }

kabdelkareem avatar Jan 14 '24 21:01 kabdelkareem

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.

jacoblee93 avatar Jan 14 '24 22:01 jacoblee93

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! :)

ElectricCodeGuy avatar Jan 21 '24 19:01 ElectricCodeGuy

With npm, I get the same error. 'npm i langchain'

With 'yarn add langchain,' everything installs correctly.

willydavid1 avatar Jan 26 '24 02:01 willydavid1

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

jacoblee93 avatar Jan 26 '24 05:01 jacoblee93

@jacoblee93 : I see a similar problem with the latest version of langchain 0.1.14

image

mdnazim5 avatar Feb 07 '24 15:02 mdnazim5

Thanks CC @bracesproul let's loosen/remove that peer dep - we can make it just a standalone script.

jacoblee93 avatar Feb 07 '24 15:02 jacoblee93

For now, you can go down to 0.1.13 @mdnazim5.

jacoblee93 avatar Feb 07 '24 16:02 jacoblee93

@mdnazim5 [email protected] should remove this dep.

jacoblee93 avatar Feb 07 '24 19:02 jacoblee93

Hi, @Monokai,

I'm helping the langchainjs team manage their backlog and am marking this issue as stale. From what I understand, the issue involves a dependency conflict when installing langchain in a project that already contains mongodb. The error suggests conflicting peer dependencies between langchain and mongodb. The maintainers have acknowledged the issue and are actively working on factoring more integrations into their own packages to address the problem in the next minor release.

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 the issue will be automatically closed in 7 days.

Thank you for your understanding and contribution to langchainjs!

dosubot[bot] avatar May 08 '24 16:05 dosubot[bot]

This was closed by the bot as not planned, but I'm opening it up again, quoting @jacoblee93:

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.

Monokai avatar May 15 '24 16:05 Monokai

@jacoblee93, could you please assist with this issue? The user has indicated that the issue is still relevant and provided some additional context. Thank you!

Details

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[bot] avatar May 15 '24 16:05 dosubot[bot]