Fix npm ci when package.json and package-lock.json disagree
If an AI coding agent changed package.json and CI says Missing: … from lock file, first check whether you want that dependency change. If you do, run npm install --package-lock-only --ignore-scripts from the directory that owns package-lock.json. Review both files, then run npm ci with the same Node and npm versions and install flags as CI. Keep the manifest and lockfile in the same pull request.
The manifest says which packages the project needs and which versions it accepts. The lockfile records the dependency tree npm resolved. npm ci checks whether that tree satisfies the project and installs it without writing a new lockfile. A test run in the agent's checkout can still pass if the old node_modules already contains the package. npm ci documentation.
Pick the fix from the first error
| What failed | What to inspect |
|---|---|
npm ci prints EUSAGE followed by Missing: … from lock file or an incompatible locked version |
Compare the manifest and lockfile. Confirm that CI checked out the expected commit and ran in the directory that owns the lockfile. |
npm ci says it needs an existing lockfile |
Check if the lockfile is tracked and present in the CI working directory or Docker build stage. If this repo uses another package manager, match the repo's documented install command in CI. |
npm ci prints ERESOLVE |
Read which packages disagree about a peer dependency, a library version they expect the project to provide. Compare the CI flags with the project's .npmrc and fix the conflicting versions if needed. |
npm ci passes but the app reports MODULE_NOT_FOUND or ERR_MODULE_NOT_FOUND |
Check whether the importing package declares the dependency and whether the install used --omit=dev. For a relative import, check the path and filename casing. |
Fix the existing package-lock.json
From the project root, inspect the current changes before running an install.
git status --short
git diff HEAD -- package.json package-lock.json
node --version
npm --version
Read git status too. A newly created untracked lockfile won't appear in that diff. In an npm workspaces repo, also inspect the manifest of the workspace that imports the package. Run the install from the workspace root where npm keeps the shared lockfile. npm workspaces documentation.
If the dependency is intentional and its version range is already correct in the manifest, regenerate the lock from the existing files.
npm install --package-lock-only --ignore-scripts
git diff HEAD -- package.json package-lock.json
npm ci
--package-lock-only lets npm resolve the tree without reinstalling node_modules. Review added direct dependencies, resolved versions, and any unrelated churn before staging the files. Starting with the existing lockfile gives npm the prior resolutions to reuse where they still satisfy the manifest. If the dependency wasn't part of the requested work, remove the unwanted import and manifest edit first. npm install documentation.
Run the clean install where it can replace node_modules without interrupting a dev server. Use CI's actual install command for verification, since install scripts can matter for native packages. If the project already uses a tree-shaping option such as install-links, use the same setting when regenerating and when running npm ci. npm ci configuration.
Reproduce a lockfile error that a local test misses
Run this in a new empty scratch directory. The temporary install makes the package available locally. The next command changes the manifest without updating the lockfile, as an agent's text edit might.
npm init -y
npm install --package-lock-only --ignore-scripts
npm install --no-save --ignore-scripts [email protected]
npm pkg set "dependencies.is-number=7.0.0"
Save this as check.cjs.
console.log(require('is-number')('42'))
node check.cjs
npm ci --ignore-scripts
On Node 22.14.0 with npm 11.7.0, the first command printed true. The second exited 1 with EUSAGE and Missing: [email protected] from lock file. The two files were out of sync even though the package loaded.
npm install --package-lock-only --ignore-scripts
npm ci
node check.cjs
That sequence added the missing lock entry without changing the manifest. The clean install succeeded, left the repaired lockfile byte-for-byte intact, and the script printed true again.
When npm ci passes but the package is missing in production
In the same scratch project, move is-number to devDependencies and try both install modes. The first run prints true. The production-only install also exits 0, but its subsequent runtime check fails with MODULE_NOT_FOUND. The lockfile stays identical across the two installs.
npm install --save-dev --save-exact --ignore-scripts [email protected]
npm ci --include=dev
node check.cjs
npm ci --omit=dev
node check.cjs
--omit=dev keeps development packages in the lockfile but leaves them off disk unless the installed tree also needs them for another reason. Move a package your running server imports to dependencies. If the missing package is only a build tool, install dev dependencies in the build stage and run the finished app in the runtime stage. npm on dependencies and devDependencies and npm's omit setting.
npm install --save-prod --save-exact [email protected]
npm ci --omit=dev
node check.cjs
The final check prints true. For your own project, use the production start command or call the route that imports the dependency. A build alone can miss a package loaded only when that route runs.
Give your coding agent a clean-install acceptance check
Inspect the manifest and lockfile against the base branch. Update the existing lockfile with the npm version and options from CI. Match our runtime dependency declarations to the packages we import. Show the manifest and lockfile diff, then run the CI install and the relevant test. If production omits dev dependencies, run a smoke test with that install too.
If the clean install passes and the deployed browser still calls the wrong API URL, check Vite's production build and environment variables. For checking the behavior of the patch itself, see how to test AI-generated code.