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 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.
npm cache verify
# if that does not clear it:
npm cache clean --force
rm -rf node_modules
npm ciRetry past transient corruption
- Re-run the job after cleaning - a one-off truncation usually does not recur.
- Bust the CI cache key if the error repeats from a restored cache.
- Update npm if you are on an old version with known cache bugs.
How to prevent it
- Run
npm cache verifyperiodically or bust caches on failure. - Avoid killing installs mid-run; let them finish or clean up after.
- Keep npm reasonably current.