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 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.
- uses: actions/setup-node@v4
with:
node-version: '22'
- run: |
node --version
npm --versionRepair a broken global npm
- Reinstall npm at a version compatible with the active Node.
- If a self-upgrade broke it, use the Node installer/
nvmto restore the bundled npm. - Avoid mixing a global
npm install -g npm@latestwith 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.