Skip to content
Latchkey

npm "cb.apply is not a function" - Fix the Internal npm Crash in CI

npm crashed inside its own code with cb.apply is not a function - a sign that the npm install is broken or mismatched with the Node version, not that your project is at fault.

What this error means

Any npm command (even npm --version) fails with TypeError: cb.apply is not a function and an npm-internal stack. It typically appears after a botched npm self-upgrade or when a global npm does not match the running Node.

npm output
npm ERR! cb.apply is not a function
npm ERR! TypeError: cb.apply is not a function
npm ERR!     at /usr/lib/node_modules/npm/node_modules/.../gracefulify.js:...

Common causes

npm and Node versions are mismatched

A global npm upgraded independently of Node (or vice versa) can leave npm running on an incompatible Node, breaking its internals before it does any work.

A corrupted global npm install

A half-finished npm install -g npm or a partially-written global tree leaves npm’s own files inconsistent, so it throws on startup.

How to fix it

Reinstall a matching Node + npm

The cleanest fix in CI is to install a known Node version through the setup action, which ships a compatible npm, rather than self-upgrading npm in place.

.github/workflows/ci.yml
- uses: actions/setup-node@v4
  with:
    node-version: '22'
- run: |
    node --version
    npm --version

Repair a broken global npm

  1. Reinstall npm at a version compatible with the active Node.
  2. If a self-upgrade broke it, use the Node installer/nvm to restore the bundled npm.
  3. Avoid mixing a global npm install -g npm@latest with an old Node in the same image.

How to prevent it

  • Pin Node via the setup action so its bundled npm always matches.
  • Avoid ad hoc global npm self-upgrades on top of an old Node.
  • Use packageManager / Corepack to pin the package manager version.

Related guides

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