Skip to content

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

Closed

Description

@e1himself

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

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.

Activity

  1. added
    Bugthing that needs fixing
    Needs Triageneeds review for next steps
    Release 8.xwork is associated with a specific npm 8 release
    on Nov 30, 2021
  2. christek commented on Dec 15, 2021

    @christek

    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
    > npm i @carbon/charts-react@0.53.4
    npm ERR! code ERESOLVE
    npm ERR! ERESOLVE unable to resolve dependency tree
    npm ERR!
    npm ERR! While resolving: peertest@1.0.0
    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@"^16.0.0 || ^17.0.0" from @carbon/charts-react@0.53.4
    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 react-dom@17.0.2
    npm ERR! node_modules/react-dom
    npm ERR!   peer react-dom@"^16.0.0 || ^17.0.0" from @carbon/charts-react@0.53.4
    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:
    ...
  3. Donorlin commented on Jan 21, 2022

    @Donorlin

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

  4. pxDot commented on Feb 3, 2022

    @pxDot

    Latest v8.4.0 sadly still with the same issue.

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

  5. ljharb commented on Feb 3, 2022

    @ljharb
    Contributor

    @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 react-dom@17.0.2 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.

  6. e1himself commented on Feb 4, 2022

    @e1himself
    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.

  7. e1himself commented on Feb 4, 2022

    @e1himself
    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
  8. ljharb commented on Feb 4, 2022

    @ljharb
    Contributor

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

  9. e1himself commented on Feb 8, 2022

    @e1himself
    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!

  10. added and removed
    Needs Triageneeds review for next steps
    on Mar 16, 2022
  11. e1himself commented on Apr 26, 2022

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingPriority 1high priority issueRelease 8.xwork is associated with a specific npm 8 release

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions