# Self-Healing CI: Recovering from npm ci Lockfile Drift

> "Missing: pkg from lock file" means package.json and package-lock.json disagree and npm ci refuses to guess. See the manual fix and how self-healing CI recovers the step.

Source: https://latchkey.dev/learn/self-healing-ci/self-healing-npm-ci-lockfile-drift  
Updated: 2026-09-02

npm ci fails on lockfile drift by design: it installs exactly what the lockfile says and refuses to resolve a package.json that no longer agrees with it.

## What makes a failure safely retryable

Automatic retry is only correct for failures that are genuinely transient. Retrying a deterministic failure wastes minutes and hides a real defect, so the classification matters more than the retry mechanism.

- Safe to retry: network timeouts, registry 5xx, transient DNS failures, a service container that was not ready, a spot instance reclaimed mid-run.
- Not safe to retry: assertion failures, compile errors, lint violations, anything that fails identically on every attempt.
- Ambiguous, and worth investigating rather than retrying: out-of-memory kills, disk exhaustion, and flaky tests. These repeat under load and a retry only hides the trend.
- Always record that a retry happened. A pipeline that silently retries is a pipeline whose real failure rate you do not know.

## FAQ

### Should I just use npm install in CI to avoid this?

No. npm ci failing here is the feature: it tells you the lockfile is out of date. Switching to npm install hides the drift and gives up reproducible installs, so two runs of the same commit can resolve differently.

---

Latchkey runs CI/CD that repairs its own failures. Agent entry points: https://latchkey.dev/agent.txt, https://latchkey.dev/openapi.json, https://latchkey.dev/llms.txt
