Issue
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
Resolution
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:
- Make sure that you're running npm >= 6 on your local machine. (This comes by default with Node 12 and 14.)
- Run npm install and check in any changes to the
package-lock.json
. - Remove the
"npm"
key from the"engines"
inpackage.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.