Repository navigation
[BUG] Multiple related packages install fail due to wrong peerDependencies resolution #3666
Description
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
mkdir npmissuecd npmissueecho "@sarunint:registry=https://gitlab.com/api/v4/projects/28910102/packages/npm/" > .npmrcnpm init -ynpm 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- Replace
1.0.0with1.0.1for only first 3 packages. 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
KristenLeach commentedon Sep 14, 2021
I've updated npm to 7.23.0 and I am still seeing this error. Are there any updates?
brandones commentedon Oct 7, 2021
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:
OrangeDog commentedon Oct 7, 2021
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?
lukekarrys commentedon Oct 8, 2021
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
--forceI get an identicalpackage-lock.jsonas 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.OrangeDog commentedon Oct 8, 2021
And another, when attempting
npm dedupe:jpage-godaddy commentedon Nov 17, 2021
Similar for me. There's a package
defwith a*version forjklinpeerDependencies, and despite the fact that a newer version ofjklis installed, thepeerDependenciesfor the very earliest publish ofjklare being demanded. This is innpm@8.1.3.TrevorKarjanis commentedon Dec 13, 2021
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.0with@angular/compiler-cli@"^13.0.0 || ^13.1.0-next".e1himself commentedon Dec 14, 2021
I believe the issue I've reported here might be related too: #4104
kolkov commentedon Feb 3, 2022
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
haskelcurry commentedon Apr 11, 2022
Hi, any updates on this?
cklogs commentedon Apr 28, 2022
Hi there,
This issue is still affecting Angular users. Can we perhaps get a status update?
XhmikosR commentedon Apr 28, 2022
@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:
vugar005 commentedon May 7, 2022
@cklogs @XhmikosR . For now, we can use
--forceflag. For example:npx @angular/cli@13 update @angular/core@13 @angular/cli@13 --forceBojanKogoj commentedon May 18, 2022
We used
--legacy-peer-deps(as suggested in error message) and it works this way for now.Weerasinghe066 commentedon Apr 25, 2023
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
fspreck-indiscale commentedon May 11, 2023
The same happens with
react@"^18.2.0"and"@testing-library/react": "^14.0.0":npm: 9.6.6
node: v19.9.0
silvenon commentedon Apr 29, 2024
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:
What is it about these dependencies that makes it so hard for npm to resolve?
Additional info, if it matters:
moshe-foreflight commentedon Dec 26, 2024
Another example of this is a conflict between
tree-sitter-swiftandtree-sitter-objc. The former pins^tree-sitter@0.21.1and the latter^tree-sitter@0.22.1.There's an unexpected workaround here which is to first install
tree-sitter-cli, usingnpm i tree-sitter-cli. I don't know enough aboutnpmor the specific package implementations to understand why, but this seems to work.Repro
Output: (2024-12-26T14_45_27_618Z-debug-0.log)
Environment