Skip to content

[BUG] npm install fails to resolve compatible peerDependencies requirements #4104

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

Closed
2 tasks done
e1himself opened this issue Nov 30, 2021 · 9 comments
Closed
2 tasks done
Labels
Bug thing that needs fixing Priority 1 high priority issue Release 8.x work is associated with a specific npm 8 release

Comments

@e1himself
Copy link

e1himself commented Nov 30, 2021

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.4
npm 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: [email protected]
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 [email protected]
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 [email protected]
npm ERR! node_modules/react-dom
npm ERR!   peer react-dom@"^0.14.9 || >=15.3.0" from [email protected]
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

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.
@christek
Copy link

christek commented 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 [email protected] matches react ^16.0.0 there should be no error.

Using
node 16.13.1
npm 8.3.0

Summary
> npm i @carbon/[email protected]
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/react
npm ERR!   react@"^16.14.0" from the root project
npm ERR!   peer react@"^16.0.0 || ^17.0.0" from @carbon/[email protected]
npm ERR!   node_modules/@carbon/charts-react
npm ERR!     @carbon/charts-react@"0.53.4" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"17.0.2" from [email protected]
npm ERR! node_modules/react-dom
npm ERR!   peer react-dom@"^16.0.0 || ^17.0.0" from @carbon/[email protected]
npm ERR!   node_modules/@carbon/charts-react
npm ERR!     @carbon/charts-react@"0.53.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 /root/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
...

@Donorlin
Copy link

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

  "peerDependencies": {
    "react": "^16.9.0 || ^17",
    "react-dom": "^16.9.0 || ^17"
  },

(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
Copy link

pxDot commented Feb 3, 2022

Latest v8.4.0 sadly still with the same issue.

You can use --legacy-peer-deps as a workaround until this is fixed.

@ljharb
Copy link
Contributor

ljharb commented Feb 3, 2022

@christek you always have to include react-dom specifically; that's the proper solution even if npm gets better at selecting it.

@e1himself your issue is caused by having react@^16.9.0 in the root, but [email protected] also, 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
Copy link
Author

@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
Copy link
Author

But installing react-dom manually 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.4

@ljharb
Copy link
Contributor

ljharb commented 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
Copy link
Author

Thanks for your input @ljharb 👍

Requiring react-dom explicitly 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
Copy link
Author

I don't seem to be able to reproduce the issue anymore. Thanks to the suggestion @ljharb made above. Closing. Thanks everyone 🙇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Priority 1 high priority issue Release 8.x work is associated with a specific npm 8 release
Projects
None yet
Development

No branches or pull requests

6 participants