Skip to content

[BUG] Multiple related packages install fail due to wrong peerDependencies resolution #3666

Open

Description

@sarunint

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

Reopening #3171 (cc @cyrilletuzi)

(The content below is modified from #3171)

When having multiple packages relying on each others having the exact same version, trying to update them all via npm install fails when there is another package which loosely rely on them via "peerDependencies": "^x.x.x", due to npm7 erroneous resolution.

Real world example: Angular core packages are supposed to be installed with the exact same version, so for example @angular/common@12.1.1 has "peerDependencies": { "@angular/core": "12.1.1" } (note the exact version).

Until now everything is fine. You can update all versions to 12.2.1 in package.json, run npm install and it works.

But now add another package which relies on one of the core packages, for example @angular-devkit/build-angular@11.2.9 has a "peerDependencies": { "@angular/compiler-cli": "^11.0.0 || ^12.0.0-next" }.

Now if you update all versions to 11.2.10 in package.json and run npm install, it fails.

(The striketrough text issue has been solved in npm@7.20.3, as stated in #3171 (comment).)

This time, there are two more dependencies that become related in this, namely:

  • @angular/animations@12.1.1. Similar to @angular/common@12.1.1, this package has "peerDependencies": { "@angular/core": "12.1.1" }
  • ngx-clipboard@14.0.1, which is a clipboard library for Angular. This one has the following:
"peerDependencies": {
    "@angular/common": ">=10.0.0",
    "@angular/core": ">=10.0.0"
}

If you modify all 12.1.1 versions to 12.2.2 and run npm install, I get the following error:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: npm-test@0.0.0
npm ERR! Found: @angular/animations@12.1.1
npm ERR! node_modules/@angular/animations
npm ERR!   @angular/animations@"12.2.2" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! @angular/animations@"12.2.2" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: @angular/core@12.2.2
npm ERR! node_modules/@angular/core
npm ERR!   peer @angular/core@"12.2.2" from @angular/animations@12.2.2
npm ERR!   node_modules/@angular/animations
npm ERR!     @angular/animations@"12.2.2" 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/sarunint/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/sarunint/.npm/_logs/2021-08-19T20_20_01_099Z-debug.log

I've created test packages to try to debug this issue, and published them to my GitLab registry.

I also discovered that the order of the package names does matter, surprisingly! As you can see with my test packages, I've dedicated package-4 to ngx-clipboard in the above example, and package-{1,2,3} to 3 @angular/* packages, with all 6 permutations (order-{a,b,c,d,e,f}). It turns out that only permutation d and f does reproduce the issue.

Expected Behavior

npm install should work, as versions are correct and peerDependencies are respected.

Steps To Reproduce

  1. mkdir npmissue
  2. cd npmissue
  3. echo "@sarunint:registry=https://gitlab.com/api/v4/projects/28910102/packages/npm/" > .npmrc
  4. npm init -y
  5. npm install -E @sarunint/order-f-package-1@1.0.0 @sarunint/order-f-package-2@1.0.0 @sarunint/order-f-package-3@1.0.0 @sarunint/order-f-package-4@1.0.0
  6. Replace 1.0.0 with 1.0.1 for only first 3 packages.
  7. npm install: should fail with following error:
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: npmissue@1.0.0
npm ERR! Found: @sarunint/order-f-package-1@1.0.0
npm ERR! node_modules/@sarunint/order-f-package-1
npm ERR!   @sarunint/order-f-package-1@"1.0.1" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! @sarunint/order-f-package-1@"1.0.1" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: @sarunint/order-f-package-3@1.0.1
npm ERR! node_modules/@sarunint/order-f-package-3
npm ERR!   peer @sarunint/order-f-package-3@"1.0.1" from @sarunint/order-f-package-1@1.0.1
npm ERR!   node_modules/@sarunint/order-f-package-1
npm ERR!     @sarunint/order-f-package-1@"1.0.1" 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/sarunint/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/sarunint/.npm/_logs/2021-08-19T19_47_04_754Z-debug.log

(You can try replace order-f with other variants. Only order-d and order-f will reproduce the issue.)

Environment

  • OS: Arch
  • Node: 14.17.5
  • npm: 7.21.0

Activity

  1. added
    Bugthing that needs fixing
    Needs Triageneeds review for next steps
    Release 7.xwork is associated with a specific npm 7 release
    on Aug 19, 2021
  2. KristenLeach commented on Sep 14, 2021

    @KristenLeach

    I've updated npm to 7.23.0 and I am still seeing this error. Are there any updates?

  3. brandones commented on Oct 7, 2021

    @brandones

    The error is still present on 7.24.2. @sarunint 's reproduction is very easy to understand once you look at the code in the repository: https://gitlab.com/sarunint/npm-dependency-bug . Here's a diagram:

    244353575_459210118682493_779233922669583813_n

  4. OrangeDog commented on Oct 7, 2021

    @OrangeDog

    I don't know if this is the same issue, but I appear to have a peer version of "*" being expanded into "0.0.0" and then failing?

    npm ERR! code ERESOLVE
    npm ERR! ERESOLVE could not resolve
    npm ERR!
    npm ERR! While resolving: @angular-eslint/eslint-plugin@2.1.1
    npm ERR! Found: eslint-plugin-jsdoc@36.1.0
    npm ERR! node_modules/eslint-plugin-jsdoc
    npm ERR!   dev eslint-plugin-jsdoc@"^36.1.0" from the root project
    npm ERR!   peer eslint-plugin-jsdoc@"*" from @angular-eslint/eslint-plugin@2.1.1
    npm ERR!   node_modules/@angular-eslint/eslint-plugin
    npm ERR!     dev @angular-eslint/eslint-plugin@"^2.1.1" from the root project
    npm ERR!     @angular-eslint/eslint-plugin@"2.1.1" from @angular-eslint/schematics@2.1.1
    npm ERR!     node_modules/@angular-eslint/schematics
    npm ERR!       dev @angular-eslint/schematics@"^2.1.1" from the root project
    npm ERR!
    npm ERR! Could not resolve dependency:
    npm ERR! peer eslint-plugin-jsdoc@"*" from @angular-eslint/eslint-plugin@2.1.1
    npm ERR! node_modules/@angular-eslint/eslint-plugin
    npm ERR!   dev @angular-eslint/eslint-plugin@"^2.1.1" from the root project
    npm ERR!   @angular-eslint/eslint-plugin@"2.1.1" from @angular-eslint/schematics@2.1.1
    npm ERR!   node_modules/@angular-eslint/schematics
    npm ERR!     dev @angular-eslint/schematics@"^2.1.1" from the root project
    npm ERR!
    npm ERR! Conflicting peer dependency: eslint-plugin-jsdoc@0.0.0
    npm ERR! node_modules/eslint-plugin-jsdoc
    npm ERR!   peer eslint-plugin-jsdoc@"*" from @angular-eslint/eslint-plugin@2.1.1
    npm ERR!   node_modules/@angular-eslint/eslint-plugin
    npm ERR!     dev @angular-eslint/eslint-plugin@"^2.1.1" from the root project
    npm ERR!     @angular-eslint/eslint-plugin@"2.1.1" from @angular-eslint/schematics@2.1.1
    npm ERR!     node_modules/@angular-eslint/schematics
    npm ERR!       dev @angular-eslint/schematics@"^2.1.1" from the root project
    
    
  5. added and removed
    Needs Triageneeds review for next steps
    on Oct 7, 2021
  6. lukekarrys commented on Oct 8, 2021

    @lukekarrys
    Contributor

    Thanks for the thorough repro and explanation! This is definitely a bug, since it's a case npm should be able to resolve.

    Another interesting thing I found when debugging this is that if I run the problematic install command with --force I get an identical package-lock.json as I get if I install them all at the same time. I'm going to dig into making this a test case in arborist so we can get this fixed.

    echo "@sarunint:registry=https://gitlab.com/api/v4/projects/28910102/packages/npm/" > .npmrc
    
    # reset everything
    rm -rf node_modules/ package-lock.json package.json
    npm init -y
    
    # install the end result we want directly, this works
    npm install -E @sarunint/order-f-package-1@1.0.1 @sarunint/order-f-package-2@1.0.1 @sarunint/order-f-package-3@1.0.1 @sarunint/order-f-package-4@1.0.0 --loglevel silly
    cp package-lock.json this-was-successful.json
    
    # reset everything again
    rm -rf node_modules/ package-lock.json package.json
    npm init -y
    
    # install all 1.0.0
    npm install -E @sarunint/order-f-package-1@1.0.0 @sarunint/order-f-package-2@1.0.0 @sarunint/order-f-package-3@1.0.0 @sarunint/order-f-package-4@1.0.0 --loglevel silly
    # then install packages 1,2,3@1.0.1, but with force
    npm install -E @sarunint/order-f-package-1@1.0.1 @sarunint/order-f-package-2@1.0.1 @sarunint/order-f-package-3@1.0.1 --force --loglevel silly
    cp package-lock.json force.json
    
    cmp this-was-successful.json force.json
    # shows 0 since files are identical
    echo $?
  7. OrangeDog commented on Oct 8, 2021

    @OrangeDog

    And another, when attempting npm dedupe:

    npm ERR! Conflicting peer dependency: typescript@4.4.3
    npm ERR! node_modules/typescript
    npm ERR!   peer typescript@"*" from @angular-eslint/builder@4.3.0
    npm ERR!   node_modules/@angular-eslint/builder
    npm ERR!     dev @angular-eslint/builder@"^4.3.0" from the root project
    
  8. self-assigned this
    on Oct 20, 2021
  9. jpage-godaddy commented on Nov 17, 2021

    @jpage-godaddy

    Similar for me. There's a package def with a * version for jkl in peerDependencies, and despite the fact that a newer version of jkl is installed, the peerDependencies for the very earliest publish of jkl are being demanded. This is in npm@8.1.3.

    » npm audit fix
    
    npm ERR! code ERESOLVE
    npm ERR! ERESOLVE unable to resolve dependency tree
    npm ERR! 
    npm ERR! While resolving: my-app@0.1.0
    npm ERR! Found: react-intl@4.7.6
    npm ERR! node_modules/react-intl
    npm ERR!   peer react-intl@"^4.5.3" from abc@2102.0.4
    npm ERR!   node_modules/abc
    npm ERR!     peer abc@">=2002.0.0" from def@4.18.4
    npm ERR!     node_modules/def
    npm ERR!       def@"^4.18.0" from the root project
    npm ERR!       1 more (ghi)
    npm ERR! 
    npm ERR! Could not resolve dependency:
    npm ERR! peer react-intl@"^2.8.0" from jkl@2000.7.21
    npm ERR! node_modules/jkl
    npm ERR!   peer jkl@"*" from def@4.18.4
    npm ERR!   node_modules/def
    npm ERR!     def@"^4.18.0" from the root project
    npm ERR!     1 more (ghi)
    
    » npm ls jkl
    
    my-app@0.1.0 /home/foo
    └─┬ def@4.18.4
      └── jkl@2102.0.4
    
  10. TrevorKarjanis commented on Dec 13, 2021

    @TrevorKarjanis

    There are additional upstream reports with a similar failure in issues 21204 and 22365. This issue seems to be the closest I can find if they are indeed issues with npm. This time it errors reconciling @angular/compiler-cli@13.1.0 with @angular/compiler-cli@"^13.0.0 || ^13.1.0-next".

  11. e1himself commented on Dec 14, 2021

    @e1himself

    I believe the issue I've reported here might be related too: #4104

  12. kolkov commented on Feb 3, 2022

    @kolkov

    angular/angular#44959 one more related issue.
    Can't update to 13.2.1 from 13.1.3 with Conflicting peer dependency: @angular/core@13.2.1

  13. haskelcurry commented on Apr 11, 2022

    @haskelcurry

    Hi, any updates on this?

  14. cklogs commented on Apr 28, 2022

    @cklogs

    Hi there,

    This issue is still affecting Angular users. Can we perhaps get a status update?

  15. XhmikosR commented on Apr 28, 2022

    @XhmikosR
    Contributor

    @lukekarrys did you have a chance to dig into this? It indeed affects angular and that's a lot of users. Would be nice if this was fixed. Using the npm version that ships with Node.js 16 LTS:

    C:\Users\xmr\Desktop\repo>node -v && npm -v
    v16.15.0
    8.5.5
    
  16. vugar005 commented on May 7, 2022

    @vugar005

    @cklogs @XhmikosR . For now, we can use --force flag. For example: npx @angular/cli@13 update @angular/core@13 @angular/cli@13 --force

  17. BojanKogoj commented on May 18, 2022

    @BojanKogoj

    We used --legacy-peer-deps (as suggested in error message) and it works this way for now.

  18. Weerasinghe066 commented on Apr 25, 2023

    @Weerasinghe066

    I got that error when upgrading to angular version from 11 to version 12.
    I changed the npm and node version and that's worked for me.
    npm version - 6.14.16
    node version - 12.22.12

  19. fspreck-indiscale commented on May 11, 2023

    @fspreck-indiscale

    The same happens with react@"^18.2.0" and "@testing-library/react": "^14.0.0":

    npm ERR! Conflicting peer dependency: react@18.2.0
    npm ERR! node_modules/react
    npm ERR!   peer react@"^18.0.0" from @testing-library/react@14.0.0
    npm ERR!   node_modules/@testing-library/react
    npm ERR!     dev @testing-library/react@"^14.0.0" from the root project
    

    npm: 9.6.6
    node: v19.9.0

  20. silvenon commented on Apr 29, 2024

    @silvenon

    The same issue is happening with npm v10.5.1 often with Remix dependencies, you should be able to reproduce this in a completely empty project. Mine were at version 2.8.0, and upgrading them results in the peer dependency errors:

    npm i @remix-run/{express,node,react,dev,testing}@latest
    
    npm ERR! Found: @remix-run/dev@2.8.0
    npm ERR! node_modules/@remix-run/dev
    npm ERR!   dev @remix-run/dev@"2.9.1" from the root project
    npm ERR!
    npm ERR! Could not resolve dependency:
    npm ERR! dev @remix-run/dev@"2.9.1" from the root project
    npm ERR!
    npm ERR! Conflicting peer dependency: @remix-run/react@2.9.1
    npm ERR! node_modules/@remix-run/react
    npm ERR!   peer @remix-run/react@"^2.9.1" from @remix-run/dev@2.9.1
    npm ERR!   node_modules/@remix-run/dev
    npm ERR!     dev @remix-run/dev@"2.9.1" from the root project
    

    What is it about these dependencies that makes it so hard for npm to resolve?

    Additional info, if it matters:

    • Node v22.0.0
    • macOS 14.4.1
  21. moshe-foreflight commented on Dec 26, 2024

    @moshe-foreflight

    Another example of this is a conflict between tree-sitter-swift and tree-sitter-objc. The former pins ^tree-sitter@0.21.1 and the latter ^tree-sitter@0.22.1.

    There's an unexpected workaround here which is to first install tree-sitter-cli, using npm i tree-sitter-cli. I don't know enough about npm or the specific package implementations to understand why, but this seems to work.

    Repro

    brew install node;
    mkdir tree-sitter-repro && cd tree-sitter-repro;
    npm init -y;
    npm i tree-sitter-objc;
    npm i tree-sitter-swift;
    

    Output: (2024-12-26T14_45_27_618Z-debug-0.log)

    Environment

    • Node v23.5.0
    • NPM 10.9.2
    • macOS 14.5
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 7.xwork is associated with a specific npm 7 release

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions