Why is my Node build is suddenly displaying "npm ERR! cb.apply is not a function"?


When installing node modules in a Node app's build, there is an error message when upgrading Node or using a newer version of Node 12 or 14. The error message may look something like this:

npm ERR! cb.apply is not a function

npm ERR! A complete log of this run can be found in:
npm ERR!     /tmp/npmcache.5MsyL/_logs/2020-07-27T18_55_42_168Z-debug.log


This is a conflict between npm <= 5 and newer versions of Node 12 and 14. The solution is to upgrade npm to >= 6, which is installed with Node 12 and Node 14 by default.

More details are described in this GitHub issue: https://github.com/nodejs/node/issues/34162#issuecomment-652575905

Take the following steps:

  1. Make sure that you're running npm >= 6 on your local machine. (This comes by default with Node 12 and 14.)
  2. Run npm install and check in any changes to the package-lock.json.
  3. Remove the "npm" key from the "engines" in package.json. The buildpack will simply use the version of npm that comes with your set version of Node. For example, both Node 12.18.3 and 14.6.0 are installed with npm 6.14.6.

Ask on Stack Overflow

Engage with a community of passionate experts to get the answers you need

Ask on Stack Overflow

Heroku Support

Create a support ticket and our support experts will get back to you

Contact Heroku Support