What this error means
npm ci can only install packages when your package.json and package-lock.json are in sync means the build or deployment failed in a clean automation environment. The cause is usually runtime version, lockfile state, secrets, project root, or deploy permissions.
Why this happens
CI/CD jobs do not inherit your local shell, installed packages, or editor credentials.
For GitHub Actions npm ci lockfile error, compare the workflow/runtime setup with the exact command that succeeds locally.
Quick fixes
- Open the failed log and find the first error line above the stack trace.
- Run npm install locally with the intended Node and npm versions, commit the updated lockfile, and rerun the workflow.
- Check Node version, working directory, lockfile state, and required secrets.
- Rerun the job only after committing the config or lockfile change.
Copy-paste commands
Check local Node version
node --version
npm --version
Reproduce a clean install
rm -rf node_modules
npm ci
Run the production build locally
npm run build
Check GitHub SSH from a runner-like shell
ssh -T git@github.com
Real-world fixes
- If the lockfile error appears only in CI, regenerate and commit the lockfile instead of switching to
npm installin CI. - If deploy keys fail, confirm the public key is attached to the target repository and the private key secret keeps newlines intact.
- Run npm install locally with the intended Node and npm versions, commit the updated lockfile, and rerun the workflow.
Step-by-step troubleshooting
- Find the first log line containing
npm ci can only install packages when your package.json and package-lock.json are in sync. - Check the job Node version and package manager command.
- Verify secrets are available for the event type; forked PRs often have restricted secrets.
- Compare the workflow working directory with the folder containing
package.json. - Run the same install and build commands locally from a clean checkout.
Platform-specific fixes
GitHub Actions
- Use
actions/setup-nodefor the intended Node version and keeppackage-lock.jsoncommitted fornpm ci.
Vercel
- Check the configured project root, build command, output directory, and environment variables in the Vercel project settings.
How to prevent it
- Keep workflow runtime versions explicit.
- Commit lockfiles and generated config needed at build time.
- Add a small CI job that runs the same build command before deploy.