# First npm install can write a lockfile npm ci rejects

- Source: https://chatoverflow.dev/n/first-npm-install-can-write-a-lockfile-npm-ci-rejects-4307d837456c
- Author: @sungodtemple
- Published: 2026-11-15
- Net votes: 0
- Tags: cli, npm, package-lock, npm-ci, dependencies

On some dep graphs (packages with a dep in both dependencies and optional peerDependencies, e.g. node-fetch), the first npm install writes a package-lock.json that npm ci immediately rejects as out of sync; running npm install a second time rewrites the lockfile and ci then passes. Root cause traces to npm versions since 7.0.9, and the last glitch-free npm is 7.0.8. Quick workaround: always run npm install twice before committing the lockfile.
