Repository navigation
[BUG] npm ci fails because npm install produces an out-of-sync lockfile (regression since v7.0.9) #8726
Description
This issue exists in the latest npm version.
Summary
npm ci intermittently refuses to install because the lockfile generated by a prior npm install is not considered “in‑sync”. Rerunning npm install once (or more) “fixes” the lockfile, after which npm ci succeeds. This undermines deterministic installs and breaks CI for projects that should be reproducible.
This is a direct follow‑up to #6787, opened 2023‑09 and labeled Priority 1. It remains open (and dead) more than two years later.
The problem persists even in the latest version v11 of npm.
Maintainer attention: the current assignee of the old issue has not responded on the thread for a long time. Multiple users have asked for reassignment. Please consider re‑triaging and reassigning so this Priority 1 bug can move forward.
Why this matters
- Breaks reproducible builds: older commits cannot be rebuilt reliably without mutating the lockfile.
- Causes flaky CI, especially when a dependency publishes a new compatible version between runs.
- Affects automation (e.g., Renovate) and monorepos/workspaces where lock determinism is essential.
Regression History / Technical Context
Community investigation in #6787 points to behavior changes beginning in v7.0.9 (first release where npm ci ignored locked versions), and further changes in 8.6.0, both touching installer logic. Reverting the implicated changes reportedly restores expected ci semantics up through later versions. Relevant commits discussed:
- v7.0.9 change:
0e58e6f(first observed wherenpm cimay install newer than locked) - v8.6.0 change:
bd96ae4(tightens checks, still leads tocifailure)
Known Workarounds (insufficient)
- Run
npm installtwice beforenpm ci. - Add specific
overridesto coerce versions? - Pin semver ranges more strictly than desired.
- Switch to an alternative package manager (e.g., pnpm) to regain determinism.
These are not acceptable long‑term substitutes for a correct npm ci.
Request
- Re‑triage and reassign this long‑standing Priority 1 issue.
- Provide guidance on the intended
cisemantics vs. semver ranges when a lockfile is present. - If feasible, add an integration test that:
- generates a lock at
t0, - publishes a new minor that satisfies the range,
- verifies
npm ciatt1installs exactly the locked versions without error.
- generates a lock at
I’m happy to help validate patches on affected projects and CI runners.
Old issue for reference: #6787
Possible origin of the error
A deeper investigation was made here: #6787 (comment)
Expected Behavior
npm installshould produce a lockfile that is immediately considered “in‑sync” bynpm ci.npm cimust install exactly the versions inpackage-lock.json, regardless of newer registry versions that satisfy semver ranges inpackage.json.
Actual Behavior
- After the first
npm install,npm cierrors with an “out of sync” message. - A second
npm installmutates the lockfile, after whichnpm cisucceeds.
Steps to Reproduce (minimal)
-
Create
package.json:{ "name": "testcase", "version": "1.0.0", "devDependencies": { "addons-linter": "6.13.0", "htmlhint": "1.1.4" } } -
Run:
npm install npm ci
You’ll see an error similar to:
npm ERR! `npm ci` can only install packages when your package.json and package-lock.json are in sync. npm ERR! Invalid: lock file's <pkg>@<x.y.z> does not satisfy <pkg>@<a.b.c> -
Run
npm installagain. -
Run
npm ciagain → now it succeeds.
A ready‑made repro (from the original report) also exposes the issue:
https://github.com/npm/cli/files/12568428/testcase.zip
Environments where this has been observed
- Multiple npm majors: 9.x, 10.x, 11.x.
- Node versions vary; the behavior tracks npm CLI, not Node runtime.
- Cross‑version scenarios (e.g., lockfile generated on npm 11.x, CI runs npm 10.x) also trigger mismatches.
(These observations consolidate multiple user reports across the original thread and related issues. See [BUG]npm installcreates unsyncpackage-lock.json#6787)
Activity
[-][BUG] `npm ci` fails because `npm install` produces an out-of-sync lockfile (regression since v7.0.9) — follow-up to #6787[/-][+][BUG] `npm ci` fails because `npm install` produces an out-of-sync lockfile (regression since v7.0.9)[/+]fix: pin node/npm to v24.11.0/v11.6.1
fix: pin node/npm to v24.11.0/v11.6.1
fix: pin node/npm to v24.11.0/v11.6.1 (#103)
ozz-oss commentedon Nov 28, 2025
#8548 #3176
danshome commentedon Nov 28, 2025
I’m seeing this same behavior on the latest npm release.
A single
npm installappears to complete successfully, but the resultingpackage-lock.jsonis not actually in sync withpackage.json. Runningnpm ciimmediately afterward fails with “package.json and package-lock.json are out of sync” error and shows several missing/invalid entries.If I run
npm installa second time—without touching any project files—npm reports additional package additions/removals/changes. After that second install,npm cisucceeds.This creates a real problem in CI because developers often run
npm installonce, commit the updated lockfile, and the CI pipeline (which usesnpm ci) fails due to the inconsistent lockfile produced by the first install.The key symptom is:
npm install(first run): completes, but produces a lockfile thatnpm cirejectsnpm install(second run): makes further unexpected changesnpm ci: then worksI can reproduce this every time with the following sequence:
ozz-oss commentedon Nov 29, 2025
#8781 #8725
ozz-oss commentedon Nov 29, 2025
#8724
michkot commentedon Dec 1, 2025
not sure if it helps, but I have reproduced that on 11.6.2 specifically compared to 11.6.0, a combination of
npm "ci" "--no-save" "--lockfile-version" "3"and a lock-file that is actually version 2 fails with a seemingly weird error complaining about a dependency missing in the lock file (the specific package I found listed as either nested dep or a optional dep).
With the same version-2 lock file, the following would still pass on 11.6.2
npm "install" "--no-save" "--lockfile-version" "3"^^ we use these two command lines in build scripts (in CI / local machines), that's why the weird combination of arguments.
For this specific case, the fix was to actually convert the lockfile to version 3 -- after that the first listed command line works fine.
I did that with
npm "install" "--lockfile-version" "3".Maybe it helps shed some light on this issue / on #8669
edit: However for other projects, it seems the lockfiles are already at version 3, however 11.6.2 expects all optional dependencies to be present in the lockfile
unav4ila8le commentedon Dec 5, 2025
I am having the same issue. Anyone has any clue for me?
https://github.com/unav4ila8le/foliofox/actions/runs/19952836659/job/57216226094
carhartl commentedon Dec 6, 2025
After we‘ve switched to using
npm ci, we‘re seeing the same, see here: https://github.com/js-cookie/js-cookie/actions/runs/19975894159/job/57291864207?pr=903It is
picomatch@4.0.3in our case.guilhermejcgois commentedon Dec 8, 2025
This comment help me solve the issue with my project: #4934 (comment) ty @lasley
Now I need to solve a lot of @types/node conflicts, yay 😅
yaronpen commentedon Dec 9, 2025
While investigating this issue in our projects, I created a validation tool that checks for inconsistencies between package.json and package-lock.json before running npm ci. It's been helpful for catching these sync problems earlier in our development workflow, especially in CI environments.
The tool validates:
Version mismatches between package.json semver ranges and locked versions
Missing dependencies that should be present in the lockfile
Structural inconsistencies that cause npm ci to fail
This is not a fix for the underlying npm bug - it's a diagnostic utility to help identify when lockfiles are out of sync so teams can address issues before CI breaks. I'm sharing it in case it helps others debug their specific cases while waiting for a proper resolution from the npm team.
Install package:
npm install npm-ci-guardGithub repository:
https://github.com/yaronpen/npm-ci-guard
22 remaining items
mwaibel-go commentedon Apr 1, 2026
For the googlers: Before re-creating the lockfile, you must also remove the node_modules directory. Otherwise the package-lock.json will not be created correctly.
feat: add postUpdateOptions npmInstallTwice for lockfile stability (#1)
fix: resolve npm ci lock file sync failures
fix: use npm install instead of npm ci in Amplify build
SamStephens commentedon Apr 27, 2026
This can also happen if a lockfile is generated with a new version of
npm, and thennpm ciis run using an older version onnpm.Remove node_modules and regen lock file
dash61 commentedon May 14, 2026
I had this problem as well when using EAS (an Expo cloud service for React Native) to build my project. It was building in the cloud, using just what I had checked in, and I needed to somehow get the correct npm version and then run npm install twice.
I managed to fix it after much work by running a pre-install script.
I was using node.js version 22.22.0, and the expo build was forcing an npm version of 10.9.4. I thought I needed a newer version of npm (I wanted 11.12.1) but it really needed to just run npm install again.
Add this to package.json in the scripts section: "eas-build-pre-install": "node ./scripts/eas-pre-install.js"
(make a scripts directory if you don't have one).
Here is the script eas-pre-install.js (taken from a SO issue here. I changed it a bit.
After making the script, use the cmd line to set the executable bits:
chmod +x eas-pre-install.jsHope this helps someone.
fix(ci): pin npm to 11.6.0 to avoid lockfile-convergence bug
📝 Document the lockfile/ci rule learned this session
Stabilize lock file (fix npm/cli#8726 convergence issue)
fix: contourner le bug npm ci sur le build backend Amplify Hosting (#53)
Fix Docker build failures for API and dashboard
fix(deps): pin esbuild via overrides to stop npm's lockfile churn
feat(bot): apps/bot workspace skeleton on grammY, Drizzle, Vitest [WF…
fix(deps): TanStack の latest 指定をキャレット範囲にし、npm 10.9.2 の npm ci が ERESO…