Skip to content
Latchkey

npm "cb() never called!" / Unexpected EOF - Fix Corrupted npm State in CI

These npm internal errors - "cb() never called!", "Unexpected end of JSON input", or unexpected EOF - generally mean npm hit corrupted cache data or a truncated download rather than a real dependency problem.

What this error means

An install aborts with an internal npm error like "cb() never called!" or "Unexpected end of JSON input". It is not a dependency conflict; it points at a damaged cache entry or a partially written file, and a clean cache often resolves it.

npm output
npm error cb() never called!
npm error This is an error with npm itself. Please report this error at:
npm error <https://github.com/npm/cli/issues>
# or:
npm error Unexpected end of JSON input while parsing ...

Common causes

Corrupted npm cache (_cacache)

A truncated or damaged entry in ~/.npm/_cacache - often from a killed install or a flaky restore of a cached cache - makes npm read invalid data.

Truncated download or interrupted install

A network drop mid-fetch, or a prior OOM/cancellation, can leave partial files that npm chokes on next run.

How to fix it

Verify or clean the cache and reinstall

Repair the cache, then do a clean install.

Terminal
npm cache verify
# if that does not clear it:
npm cache clean --force
rm -rf node_modules
npm ci

Retry past transient corruption

  1. Re-run the job after cleaning - a one-off truncation usually does not recur.
  2. Bust the CI cache key if the error repeats from a restored cache.
  3. Update npm if you are on an old version with known cache bugs.

How to prevent it

  • Run npm cache verify periodically or bust caches on failure.
  • Avoid killing installs mid-run; let them finish or clean up after.
  • Keep npm reasonably current.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →