You edit a package version in package.json by hand and forget to update package-lock.json. If your CI pipeline runs npm install, it quietly recalculates the dependency tree and pulls newer versions from the registry. Different code ends up in production.
For builds, use npm ci (Clean Install). It never edits package.json or package-lock.json. First it checks that they match, then it clears node_modules and installs the exact locked versions. When they are out of sync in npm 12.2.3, the build fails with EUSAGE without wiping node_modules for nothing.
# Risky in CI: quietly updates the lockfile
- run: npm install
# Safe in CI: strictly follows package-lock.json
- run: npm ci
If you forget to run npm install after editing package.json, the pipeline catches it on step one. Locally, the error looks like this:
# Manual edit to package.json without running npm install:
npm ci
# npm error code EUSAGE
# `npm ci` can only install packages when your
# package.json and package-lock.json are in sync.
# Fix locally:
npm install && git add package.json package-lock.json
Caching node_modules alongside npm ci is pointless because the folder gets wiped every run; cache ~/.npm instead. In pnpm, pnpm install --frozen-lockfile and pnpm ci give the same protection. In Yarn, use yarn install --immutable (both tools turn these flags on automatically in CI).



