How to fix npm ERR! code EUSAGE npm ERR! `npm ci` can only install packages when your package.json and package-lock.json are in sync in npm

npmBEGINNERMEDIUMUpdated Dec 3, 2025ยท 286 views

This error occurs when package.json has been modified without updating package-lock.json. Run npm install to regenerate the lockfile, then commit both files.

Quick fix

Fixes npm ERR! code EUSAGE npm ERR! `npm ci` can only install packages when your package.json and package-lock.json are in sync

# Delete existing lockfile and node_modules
rm -rf node_modules package-lock.json

# Regenerate
npm install
  1. Regenerate the lockfile locally
  2. Verify the sync
  3. Commit both files together
  4. Prevent future issues
npm โ€” error
# Delete existing lockfile and node_modules
rm -rf node_modules package-lock.json
# Regenerate
npm install
npm ERR! code EUSAGE
npm ERR! `npm ci` can only install packages when your package.json and package-lock.json are in sync

What this error means

npm ci is designed for automated environments (CI/CD) where reproducible builds are critical. It requires package.json and package-lock.json to be perfectly synchronized. Unlike npm install, which can update the lockfile, npm ci refuses to install if any dependencies in package.json don't match the lockfile. This ensures that builds are reproducible and don't accidentally introduce different versions. The error indicates someone modified package.json (added, removed, or changed a dependency version) but didn't run npm install to update the lockfile.

Typical symptoms

  • CI/CD pipeline fails at npm ci step
  • Error mentions "package.json and package-lock.json are in sync"
  • Builds fail after adding or updating dependencies
  • Works locally with npm install but fails in CI with npm ci
  • Pull requests fail automated checks

Common causes

  1. package.json edited manually without running npm install
  2. Dependency version changed in package.json but lockfile not updated
  3. package-lock.json not committed after adding new dependency
  4. Merge conflict resolved incorrectly, leaving files out of sync
  5. Different npm versions between developers causing lockfile format differences

How to fix "npm ERR! code EUSAGE npm ERR! `npm ci` can only install packages when your package.json and package-lock.json are in sync"

1Regenerate the lockfile locally

On your development machine:

bash
# Delete existing lockfile and node_modules
rm -rf node_modules package-lock.json

# Regenerate
npm install

This creates a fresh lockfile matching your current package.json.

2Verify the sync

Run npm ci locally to verify the fix:

bash
rm -rf node_modules
npm ci

If this succeeds, the files are in sync.

3Commit both files together

Always commit package.json and package-lock.json together:

bash
git add package.json package-lock.json
git commit -m "Fix: sync package.json and package-lock.json"
git push
4Prevent future issues

Add a pre-commit hook to prevent out-of-sync files:

bash
# Using husky
npx husky add .husky/pre-commit "npm ci --dry-run"

Or add a CI check that fails fast if files are out of sync.

Advanced notes

npm ci vs npm install:

| Feature | npm install | npm ci |
|---------|------------|--------|
| Updates lockfile | Yes | No |
| Deletes node_modules | No | Yes |
| Speed | Slower | Faster |
| Use case | Development | CI/CD |

If you need to update a single dependency without npm install:

bash
npm update <package-name>

For monorepos with workspaces, ensure all workspace package-lock.json files are in sync.

Different npm versions can generate different lockfile formats (lockfileVersion 1, 2, or 3). Standardize npm versions across your team using engines in package.json:

json
{
  "engines": {
    "npm": ">=9.0.0"
  }
}

Frequently asked questions

What does "npm ERR! code EUSAGE npm ERR! `npm ci` can only install packages when" mean?
npm ci is designed for automated environments (CI/CD) where reproducible builds are critical. json to be perfectly synchronized. json don't match the lockfile.
How do I fix "npm ERR! code EUSAGE npm ERR! `npm ci` can only install packages when"?
This error occurs when package.json has been modified without updating package-lock.json. Run npm install to regenerate the lockfile, then commit both files.
What causes "npm ERR! code EUSAGE npm ERR! `npm ci` can only install packages when"?
package.json edited manually without running npm install Dependency version changed in package.json but lockfile not updated package-lock.json not committed after adding new dependency
Is the "npm ERR! code EUSAGE npm ERR! `npm ci` can only install packages when" error serious?
It is a medium-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading