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.
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.
On your development machine:
# Delete existing lockfile and node_modules
rm -rf node_modules package-lock.json
# Regenerate
npm installThis creates a fresh lockfile matching your current package.json.
Run npm ci locally to verify the fix:
rm -rf node_modules
npm ciIf this succeeds, the files are in sync.
Always commit package.json and package-lock.json together:
git add package.json package-lock.json
git commit -m "Fix: sync package.json and package-lock.json"
git pushAdd a pre-commit hook to prevent out-of-sync files:
# 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.
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:
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:
{
"engines": {
"npm": ">=9.0.0"
}
}npm ERR! code ENOAUDIT npm ERR! Audit endpoint not supported
How to fix "npm ERR! code ENOAUDIT - Audit endpoint not supported"
npm ERR! code EBADDEVENGINES npm ERR! devEngines.runtime incompatible with current node version
How to fix "npm ERR! code EBADDEVENGINES - devEngines.runtime incompatible with current node version"
npm ERR! code ETOOMANYARGS npm ERR! Too many arguments
How to fix "npm ERR! code ETOOMANYARGS - Too many arguments"
npm ERR! code EINVALIDTAGNAME npm ERR! Invalid tag name: tag names cannot contain spaces
How to fix "npm ERR! code EINVALIDTAGNAME - tag names cannot contain spaces"
npm ERR! code E400 npm ERR! 400 Bad Request
How to fix "npm ERR! code E400 - 400 Bad Request" error