The receipt on Dodi’s spike: package-lock.json as npm writes it. When does npm install use it, what does npm ci say to a lock out of sync, and what happens to…
Why it matters
"Works on my machine" most often starts here: dependency versions that quietly differ. A committed lock plus npm ci in CI makes your laptop, your friend’s, the CI and the production server install exactly the same tree, and refuse a tarball whose contents changed.
The key idea
A range is a limit; the lock is the choice, fingerprint included
Common mistakes
Putting the lockfile in .gitignore "to keep the repo clean" The opposite: the lockfile must be committed. It is the only thing that makes the team’s and CI’s installs identical. What goes in .gitignore is node_modules/, not the lock.
CI uses npm install, not npm ci In CI use npm ci: it installs exactly from the lock, clears the old node_modules first, and stops with EUSAGE when the lock is out of sync with package.json instead of quietly updating it. Update the lock on your laptop with npm install, then commit.
Two lockfiles from different package managers in one repo Pick one: package-lock.json (npm), pnpm-lock.yaml (pnpm) or yarn.lock (yarn). Each tool reads only its own, so two locks mean two trees that can differ. Delete the other and set packageManager in package.json.
Try it in this playground
See the versions drift Install with no lock and compare with Dodi’s lock.
Let npm ci refuse Add log-symbols without updating the lock, then npm ci.
Catch the changed tarball The server serves the changed tarball; install with a lock.
The lock updated only as needed With Dodi’s lock, add log-symbols and npm install: chalk stays 4.1.0.