How to solve npm ERR! cb.apply is not a function error

When running the npm install command, you may see an error that says “cb.apply is not a function”.

The error message is as follows:

$ npm install
npm ERR! cb.apply is not a function

npm ERR! A complete log of this run can be found in:
...

This error happens when npm tries to execute the graceful-fs package in the installation process.

The changes in this commit causes cause older npm versions to fail executing graceful-fs code.

While your project may not have a direct dependency on graceful-fs, the module is used by many popular packages in the npm ecosystem.

You can look for the package that depends on graceful-fs in npm. Even npm depends on this package!

To resolve this issue, you need to update npm to v6.10.0 and above.

But since npm itself depends on graceful-fs, updating npm using npm install may cause an error as shown below:

npm install -g npm@latest

npm ERR! cb.apply is not a function

When this happens, then your next option is to download the latest version of Node from nodejs.org.

The latest LTS version should be enough to resolve the issue.

Delete the roaming npm folder on Windows

If you did’t see the npm version updated after installing the latest Node version, then you may need to delete the npm folder located in C:\Users\<user>\AppData\Roaming

This is because your computer will prioritize using npm stored in the Roaming folder over the one in your nodejs folder.

It happens to me when I installed the latest Node version. I found the npm version stays while node has been updated.

Once you removed the npm folder in Roaming, restart your command line.

You should see the latest npm version printed by running the npm -v command.

Now the npm install command should work.

And that’s how you solve the npm ERR! cb.apply is not a function. 👍

Take your skills to the next level ⚡️

I'm sending out an occasional email with the latest tutorials on programming, web development, and statistics. Drop your email in the box below and I'll send new stuff straight into your inbox!

No spam. Unsubscribe anytime.