Repository navigation
[BUG] npm install fails to resolve compatible peerDependencies requirements #4104
Copy link
Copy link
Closed
Labels
Bugthing that needs fixingthing that needs fixingPriority 1high priority issuehigh priority issueRelease 8.xwork is associated with a specific npm 8 releasework is associated with a specific npm 8 release
Description
Is there an existing issue for this?
- I have searched the existing issues
There is an existing issue #3171 which looks similar. Even though it's marked as resolved, I still have this problem.
This issue exists in the latest npm version
- I am using the latest npm
Current Behavior
npm install fails to resolve two version ranges of one dependency into a version that is compatible with both requirements.
When I try to add another package to a project with "react": "^16.9.0" I get a conflict, even though the ranges are compatible (peerDependencies of the package being installed is "react": "^0.14.9 || >=15.3.0").
It looks like npm first independently resolves both ranges to the latest possible version that satisfies the requirements and then checks if they are compatible.
Expected Behavior
npm should check if the already installed dependency version satisfies the required peerDependency range in the package being installed.
Steps To Reproduce
mkdir peer-dependency-conflict-demo
cd peer-dependency-conflict-demo
npm add react@^16.9.0
npm add react-bootstrap@=0.32.4npm ERR! code ERESOLVE
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: undefined@undefined
npm ERR! Found: react@16.14.0
npm ERR! node_modules/react
npm ERR! react@"^16.14.0" from the root project
npm ERR! peer react@"^0.14.9 || >=15.3.0" from react-bootstrap@0.32.4
npm ERR! node_modules/react-bootstrap
npm ERR! react-bootstrap@"=0.32.4" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"17.0.2" from react-dom@17.0.2
npm ERR! node_modules/react-dom
npm ERR! peer react-dom@"^0.14.9 || >=15.3.0" from react-bootstrap@0.32.4
npm ERR! node_modules/react-bootstrap
npm ERR! react-bootstrap@"=0.32.4" 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.
npm ERR!
npm ERR! See /home/ivan/.npm/eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/ivan/.npm/_logs/2021-11-17T15_45_03_518Z-debug.log
react-bootstrappackage.json: https://github.com/react-bootstrap/react-bootstrap/blob/v0.32.4/package.json#L54-L57
Environment
- npm: v16.13.0
- Node: v8.1.4
- OS: Fedora Linux 35, Kernel 5.15.3
- platform: Asus ROG Zephyrus G14
- npm config:
; "user" config from /home/ivan/.npmrc
//registry.npmjs.org/:_authToken = (protected)
; node bin location = /home/ivan/.nvm/versions/node/v16.13.0/bin/node
; cwd = /home/ivan/workspace/sandbox/peer-dependency-conflict-demo
; HOME = /home/ivan
; Run `npm config ls -l` to show all defaults.Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Bugthing that needs fixingthing that needs fixingPriority 1high priority issuehigh priority issueRelease 8.xwork is associated with a specific npm 8 releasework is associated with a specific npm 8 release
Activity
christek commentedon Dec 15, 2021
I confirm there also is an error when peerDependencies of the package being installed is "react": "^16.0.0 || ^17.0.0" (and the root package has react@^16.9.0 as in the example above). Since react@16.9.0 matches react ^16.0.0 there should be no error.
Using
node 16.13.1
npm 8.3.0
Summary
Donorlin commentedon Jan 21, 2022
Any news about this issue, please?
I have probably the same issue.
My package has peer dependency for
"react": "^16.14.0"(just react, because specifying react-dom should not be needed since I am not using it in any way in my package)When I try to install any package that has peer dependencies for react and react-dom specified like this
(allowing version 16 and 17) .
NPM is trying to resolve the highest react-dom version possible since I am not specifying it in my package peer dependencies (or any other dependencies) and this package allows react-dom@17 (and 16).
I do not know if this is intended functionality, but in my opinion, NPM should try to resolve react-dom compatible with the dependencies I specified and that is react@16 so it should try to resolve react-dom@16.
Of course, everything gets resolved correctly when I add react-dom in my peer dependencies (or any other dependencies).
pxDot commentedon Feb 3, 2022
Latest v8.4.0 sadly still with the same issue.
You can use
--legacy-peer-depsas a workaround until this is fixed.ljharb commentedon Feb 3, 2022
@christek you always have to include
react-domspecifically; that's the proper solution even if npm gets better at selecting it.@e1himself your issue is caused by having
react@^16.9.0in the root, butreact-dom@17.0.2also, and those two are incompatible. You also need to add an explicit react-dom dependency.This is just how it's done in the react ecosystem, due to the way react has set up all their dependency/peerDep relationships.
e1himself commentedon Feb 4, 2022
@ljharb I'm confused with your comment. Please see the reproduction steps in the issue description. There is no dependency requiring React 17. It's a bug of npm being unable to properly resolve an intersection of two version requirements.
e1himself commentedon Feb 4, 2022
But installing
react-dommanually does solve the problem indeed 🤔mkdir peer-dependency-conflict-demo cd peer-dependency-conflict-demo npm add react@^16 react-dom@^16 npm add react-bootstrap@=0.32.4ljharb commentedon Feb 4, 2022
@e1himself yes, i understand that npm is selecting react-dom 17, and that creates the incompatibility. But, in the react ecosystem, you always, without exception have to explicitly specify react-dom, even if npm were to fix this.
e1himself commentedon Feb 8, 2022
Thanks for your input @ljharb 👍
Requiring
react-domexplicitly does solve the problem for the reproduction steps I've provided in the issue description.I will check if this trick will work for my actual production app and comment here later.
Thanks!
e1himself commentedon Apr 26, 2022
I don't seem to be able to reproduce the issue anymore. Thanks to the suggestion @ljharb made above. Closing. Thanks everyone 🙇