npm ci can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync
Last verified:
The fix
npm ci refused to install because package.json and the lockfile describe different dependencies. Update the lockfile on purpose and commit it. That pin is the safer install.
- 1
Read the Missing or Invalid lines
The paragraph under the error names the package.
Missingmeanspackage.jsonasks for something the lockfile does not have.Invalidmeans the locked version does not satisfy the range now inpackage.json. That pair is the edit. Do not deletenode_modulesand hope a second run agrees. - 2
Update the lockfile with npm install
From the project root, run
npm install. That is the command the error tells you to run.npm ciwill not edit the lockfile for you. Commit bothpackage.jsonandpackage-lock.json. Do not delete the lockfile to get a "clean" tree. A missing lockfile is how the next install floats to whatever version satisfies the range today.npm install - 3
Re-run npm ci
npm ciremoves an existingnode_modules, then installs the locked tree. It should finish without rewriting the lock. If the lockfile was created with--legacy-peer-depsor--install-links, npm's docs say you must pass those same flags tonpm cior the trees will not match. Do not add those flags just to get past this error. A peer conflict has its own page. - 4
Use npm ci where the app is built
Locally,
npm installis how you update the lock after a deliberatepackage.jsonchange. In CI, and as the install command on a host that lets you set one,npm ciis what you want. It refuses a lockfile that no longer matches, instead of resolving a new version during the build. Commit the lockfile in the same change aspackage.json.
Why it happens
npm ci is the clean install. npm's docs: the project must already have a package-lock.json or npm-shrinkwrap.json, and if the lock's dependencies do not match package.json, npm ci exits instead of updating the lock. It never writes to either file. The error says npm ci can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync, and tells you to update the lock file with npm install before continuing. The lines under it name the drift, such as Missing: <name>@<version> from lock file or Invalid: lock file's <name>@<locked> does not satisfy <name>@<range>.
An AI edit often changes a version or adds a dependency in package.json and does not regenerate the lockfile. npm install on your laptop will quietly update the lock when the ranges no longer match. npm ci in CI will not.
Committing the lockfile and installing with npm ci is the safer default because the lock records the exact tree you installed. A range such as ^1.2.0 in package.json still allows a later release. Without a lockfile, or with a host command that re-resolves when the files disagree, the next install can pick up a version published after you last looked. npm ci installs the locked versions and fails when package.json has drifted, so that change has to be reviewed in the lockfile diff.
The next error you'll probably hit
Once this is fixed, the usual follow-up is npm error ERESOLVE unable to resolve dependency tree. npm error ERESOLVE unable to resolve dependency tree. Install a version whose peer matches this app. Do not start with --legacy-peer-deps.
Prompt to paste back into your AI tool
Paste this above the error.
npm ci failed with: `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. The detail lines are: <paste the Missing: or Invalid: lines> Do not delete package-lock.json. Do not add --legacy-peer-deps or --force. Do not run npm ci hoping it will rewrite the lock. Do not change dependency ranges you were not asked to change. 1. Name the package.json change that the lockfile does not satisfy. 2. Tell me to run npm install so the lockfile updates, then commit package.json and package-lock.json together. 3. Tell me to re-run npm ci. If it still fails, quote the new Missing or Invalid line and stop. 4. Leave the CI or host install command on npm ci. Do not rewrite unrelated files.
Common questions
+Why is committing the lockfile safer than the ranges in package.json?
A range such as ^1.2.0 accepts later releases. The lockfile records the exact versions from the install you ran. npm ci installs that tree and will not quietly take a version published later. You see the upgrade when the lockfile diff changes.
+npm install works on my laptop and CI fails. Why?
npm install updates the lockfile when package.json no longer matches. npm ci refuses and exits. Commit the package-lock.json that npm install just wrote, then run npm ci.
+Should I delete package-lock.json and node_modules?
No. That throws away the pins and lets the next install resolve ranges again. Update the lockfile with npm install and commit it.
Related errors
- npm error ERESOLVE unable to resolve dependency treenpm error ERESOLVE unable to resolve dependency tree. Install a version whose peer matches this app. Do not start with --legacy-peer-deps.CursorLovableBoltNodeReactNov 4, 2026
- Module not found: Can't resolveModule not found: Can't resolve means the import path or package is not on disk, often after an AI edit. Fix the path or install the package, then restart.CursorLovableBoltTypeScriptNext.jsOct 14, 2026
- Lovable app not deploying: read the bannerLovable app not deploying: the Publish dialog says Build errors need fixing or Publishing failed. Match that sentence, fix that cause, and publish again.LovableCursorViteSupabaseNov 2, 2026