CI/CD error npm ERR! `npm ci` can only install packages when your package.json and package-lock.json are in sync.
npm ci installs exactly what the lockfile says and refuses to guess. It stops when package.json lists something the lockfile doesn't match.
Published
Why this happens
- Someone edited package.json (or ran `npm install <pkg>` with a different tool) and didn't commit the updated package-lock.json
- The lockfile was generated with a different npm major version than the one CI uses
- A merge conflict in package-lock.json was resolved by hand, or by taking one side, leaving it inconsistent
How to fix it
- Run `npm install` locally, commit the updated package-lock.json, and push
- Pin the same Node and npm versions locally and in CI (the `engines` field, `.nvmrc`, and `actions/setup-node`)
- After a lockfile merge conflict, resolve package.json first, then regenerate the lockfile with `npm install` instead of editing it by hand
- Don't switch CI to `npm install` to get past it. That hides the drift and makes CI installs non-reproducible