Node.js builds slow with `npm` 6.x

Issue

Installing node_modules with npm versions 6.14.15, 6.14.16, 6.14.17, etc. takes an extremely long amount of time, something like 10x the normal build time.

npm version 6.14.15 introduced a security fix which happens to have a major impact on performance. The issue is outlined here: https://github.com/npm/cli/issues/3939#issuecomment-956958065.

Resolution

Pin npm to a recent, supported, and performant release. npm 8.x is suggested, as it's the actively maintained release. npm 6.14.13 is also known to fix the performance issue. However, it includes known security issues and is on the unsupported 6.x release line. To specify npm 8.x, modify package.json with:

"engines": {
  "npm": "8.x"
}

If using Node.js 14.x, npm 6.x is the default npm shipped with Node.js. Node.js 16.x ships with npm 8.x by default. Upgrading to Node.js 16 will fix this issue (if npm version is not specified). To specify Node.js 16.x, modify package.json with:

"engines": {
  "node": "16.x"
}

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