Repository navigation
[BUG] npm ci can't resolve dependencies without --force, or --legacy-peer-deps #4998
Copy link
Copy link
Closed
Labels
Bugthing that needs fixingthing that needs fixingNeeds Triageneeds review for next stepsneeds review for next stepsRelease 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
This issue exists in the latest npm version
- I am using the latest npm
Current Behavior
I've updated to latest node version which use npm 8.11.0, but the problem exist with versions >= 8.6.0 up to 8.12.1
when I do an npm install --legacy-peer-deps, all dependencies are correctly installed and I can start my app.
but when my CI try do make an npm ci, I have conflit errors
>npm ci
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: @nestjs/elasticsearch@8.1.0
npm ERR! Found: @elastic/elasticsearch@5.6.22
npm ERR! node_modules/@elastic/elasticsearch
npm ERR! @elastic/elasticsearch@"~5.6.22" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer @elastic/elasticsearch@"^7.4.0 || ^8.0.0" from @nestjs/elasticsearch@8.1.0
npm ERR! node_modules/@nestjs/elasticsearch
npm ERR! @nestjs/elasticsearch@"~8.1.0" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: @elastic/elasticsearch@8.2.1
npm ERR! node_modules/@elastic/elasticsearch
npm ERR! peer @elastic/elasticsearch@"^7.4.0 || ^8.0.0" from @nestjs/elasticsearch@8.1.0
npm ERR! node_modules/@nestjs/elasticsearch
npm ERR! @nestjs/elasticsearch@"~8.1.0" 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.Expected Behavior
I should not have any errors when I do npm ci since it should use package-lock wich contains all conflict resolutions.
If I revert to npm@8.5.5, it works correctly without having to do a new npm install
Steps To Reproduce
npm init
npm install @nestjs/elasticsearch@8.1.0 --package-lock-only
npm install @elastic/elasticsearch@5.6.22 --package-lock-only --legacy-peer-deps
npm ciyou can also try without --package-lock-only but by removing node_modules folder
Environment
- npm: 8.11.0
- Node.js: 6.15.1
- OS Name: Alpine
- System Model Name: WSL
- npm config:
; "builtin" config from /usr/local/lib/node_modules/npm/npmrc
globalignorefile = "/etc/npmignore"
prefix = "/usr/local"
python = "/usr/bin/python3"
; "user" config from /home/pierre/.npmrc
save-prefix = "~"
; node bin location = /usr/bin/node
; cwd = ***
; HOME = /home/pierre
; Run `npm config ls -l` to show all defaults.Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Bugthing that needs fixingthing that needs fixingNeeds Triageneeds review for next stepsneeds review for next stepsRelease 8.xwork is associated with a specific npm 8 releasework is associated with a specific npm 8 release
Activity
ranyefet commentedon Jun 8, 2022
This is a breaking change without bumping major version. Any update on this issue?
stormbard commentedon Jun 8, 2022
Not sure if this is related. I have a package-lock file generated using npm 8.5.0 when I try to do a
npm ciusing npm 8.11.0 I get the followingAdding
--legacy-peer-depsto thenpm cicommand allows the clean install to work as I'd expect.kopylash commentedon Jun 9, 2022
Also, having this issue. When downgrading npm to 8.1 everything works fine.

Node 16.15.1 was released which includes npm@8.11 and our CI builds started failing because we use
node:16Docker imagectretyak commentedon Jun 9, 2022
The bug (feature maybe?, but very annoying) exists since npm@8.6 (included). On npm@8.5 everything good
l-moveshelf commentedon Jun 9, 2022
I think this is the intended behaviour. The official doc states that:
mlvzk commentedon Jun 9, 2022
If this is intended and breaks
npm install(if 8.5 works and 8.6 doesn't) shouldn't it have been released in a major update, not minor?l-moveshelf commentedon Jun 9, 2022
This doesn't "break" npm install; my assumption is that it was previously working in our use case because of a bug, which has now been fixed (can't see the official documentation history, so I'm not sure if it was also stated before)
ctretyak commentedon Jun 9, 2022
Before 8.6 I could run
npm i --forceonce and after that just usednpm imany times. Now I have to use --force every time. For me, it's convenient to allow to install dangerous code once than do mindless operation every time. May you can add any flags that work like "--force" before npm@8.6 (e.g. --force-permanent)?l-moveshelf commentedon Jun 9, 2022
I believe you can with the following:
stormbard commentedon Jun 9, 2022
This is where my case is slightly different. Generated the lock-file without any special parameters, but adding the
--legacy-peer-depsallows it to work(?) with npm 8.11. Without it the process just errors.l-moveshelf commentedon Jun 9, 2022
Did you try removing the lock file as well as the node modules and retrying?
funnylookinhat commentedon Jun 9, 2022
I've seen this behavior as well - but the puzzling part is that I'm seeing it fail in builds and then succeed with a build that is retried.
In spite of the documentation (and that providing either an
.npmrcor--legacy-peer-depsfixing the problem), I would consider this a regression - as quite a few build processes have begun failing where they were previously working as intended. Docs are only as good as they adhere to the process. I don't believe including the phrasemayas a clause for possible breakage is a fair contract for determining if a change is breaking.56 remaining items
snebjorn commentedon Jun 22, 2022
What is the point of using the
legacy-peer-depsflag when it have to be applied everywhere all the time? Doesn't that make it redundant?Sure in the ideal world packages would always have updated peer dependency ranges. But in the real world packages use ranges like
peerA@">=16.0.0 <18.0.0"and thenpeerA@18is released and it works. But the author of the package is on hiatus so a new version won't come for some time.Now my build fails because of this.
It used to be a decision made when installing/updating a peer dependency. Once a person had installed a package using
--legacy-peer-depsthen subsequentnpm i/npm ciwould work because the person that installed the package with outdated peer dependencies had checked that it worked.That made sense to me. It was nice to get an error. It was nice to tell NPM "hey I checked it works and it's fine".
Now I have to put
legacy-peer-deps=truein.npmrcand I won't get an error when I try to install something with outdated peer dependencies. I also won't know if other people checked if a package worked.Can this please be reverted? It was working before.
ouzkhanmete commentedon Jun 22, 2022
Same here, suddenly all the pipelines with Node 16 in it started to throw errors. If we are forced to put the
--legacy-peer-depsin.npmrcfor every service with Node 16+ - what is the point in this flag at all? Why there are no big announcements on that? Why it was bumped in minor version, not major?My vote is to revert this change as it ruins peoples' time with no reason.
ObieMunoz commentedon Jun 22, 2022
Did you update your versions locally and rebuild your package-lock file?
nhowell commentedon Jun 23, 2022
This is exactly what people should not have to do. Their existing package-lock.json file should continue to work. Any requirement otherwise is a breaking change to
npm ciand should be reverted.mofojed commentedon Jun 23, 2022
To avoid this kind of issue in the future, I'll pin CI and dev to a specific version of node/npm (using
.nvmrcfile) instead of pinning to an lts release (previously we used16.xin GitHub actions andlts/galliumin our.nvmrc).ouzkhanmete commentedon Jun 24, 2022
No I did not. I have like 100+ dependencies broken, do you want my team to waste a month of work rebuilding the codebase over few hundred repositories? Are you joking?
We rolled back to Node v16.15.0, which has a working version of npm 8.5.5.
--legacy-peer-depsflag did not help, when rebuildingpackage-lock.jsonfrom scratch and doingnpm ciwith the very same flag afterwards.NotYevvie commentedon Jun 24, 2022
Are there any plans to deprecate / remove support for --legacy-peer-deps in the near future (0-2 years)?
paulius-valiunas commentedon Jun 27, 2022
All you have to do is install node.js 16.15.1 locally and run
npm install. Sometimes that's enough to fix this problem.ObieMunoz commentedon Jun 27, 2022
That's what I was saying but apparently that's not ok. It fixed all of our pipelines though.
fritzy commentedon Jun 30, 2022
The consistency between your
package-lock.jsonvs yourpackage.jsonhas security implications, among other things. Additionallynpmcan't infer the configuration (like--legacy-peer-deps) used innpm installwhen you later usenpm ci, which is what this specific bug report was about.It's unfortunate that this fix has caused so many
npm cifailures, but if yourpackage.jsonisn't properly represented in yourpackage-lock.json, then you'll need to regenerate yourpackage-lock.jsonwith a newnpm install. We'll take some lessons learned here about what we could do better in the future when addressing bugs that might disrupt workflows when fixed.Again, this particular report has to do with using a consistent configuration between the command that generates the lock and the command the uses the lock. As such, I'm going to close this issue. If you'd like to start a discussion around storing the configuration in the lockfile, or other possible behavior changes, please create an RRFC or start a discussion in the repo.
That's not to say that there couldn't be bugs that need to be addressed related to lockfile consistency. If you come across one, please submit a bug report.
paulius-valiunas commentedon Jun 30, 2022
it doesn't matter if you think the configurations people used were "correct" or not, as you can see a significant number of people used it this way and it worked before. Now it stopped working, which is a breaking change by definition. The correct way to fix this bug would have been either:
What you just did is incompatible with semver because it breaks people's workflows without declaring a major version bump. What's even worse is that it's not even a minor bump, just a patch.
nhowell commentedon Jun 30, 2022
It's
unfortunateunacceptable that this fix has caused so manynpm cifailures.FTFY.
This broke my workplace and many other's CI pipelines, in a patch version no less, and you expect the community to be fine with an "oh well, we'll do better next time" response. Unacceptable. Go back and fix it in a backwards compatible way.
My workplace has never used any special flags when running
npm inornpm ci(e.g.--force, or--legacy-peer-deps), yet our CI pipeline was suddenly broken due to this so called "bugfix". So much fornpm ciwith apackage-lock.jsonbeing deterministic behavior.If NPM would've came out and said, "Oops, that was an unexpected consequence of this bugfix - we'll fix it up in the next patch version" I would be completely satisfied. Instead, this issue and its response has caused me to lose all confidence in NPM CLI updates. Guess we'll be pinning an exact version of Node/NPM in our CI pipeline from here on out, or moving to Yarn.
fritzy commentedon Jun 30, 2022
I have created a pinned issue summarizing this discussion as well as #4664.
See the please refer to the pinned issue, #5113