npm ci fails in CI with "package.json and package-lock.json are not in sync". What do you do?

IntermediateTroubleshootingNode.js builds (npm, package.json)
Answer

Short answer

Someone changed package.json (added, removed or bumped a package) without committing the updated lockfile. npm ci refuses to guess. Fix it by running npm install locally with the same Node/npm version, committing the updated package-lock.json, and pushing.

Steps

node -v && npm -v                  # match the versions CI uses
npm install                        # regenerates package-lock.json
git add package-lock.json
git commit -m "Update lockfile"
git push

Other causes

  • Different npm major versions produce different lockfile formats — pin Node in CI (.nvmrc, engines) to match developers.
  • Merge conflicts in the lockfile resolved badly — delete it and regenerate with npm install, then review the diff.
  • Using Yarn/pnpm locally but npm ci in CI — use the tool that matches the committed lockfile.

Prevention

Add a PR check that runs npm ci — the PR fails before it ever reaches main.

What to say in the interview

"It means the lockfile wasn't updated with package.json. I regenerate it with npm install using the same Node version as CI and commit it. We prevent it by running npm ci on every PR and pinning the Node version."

All Build Tools (Java, Node.js, Python, .NET) questions Roadmap: Node.js apps: npm & package.json

More on Node.js builds (npm, package.json)