Unable to install npm; does it exist?

Issue

While deploying a Node.js app using npm, an error like Unable to install npm >=9; does it exist? prevents the installation of npm and fails the build.

Resolution

The selected Node.js and npm version requirements may not be compatible. For example, npm version 10.0.0 requires Node.js 18.17.0, 20.5.0, or newer. The issue can be resolved by modifying the engines section in package.json in one of the following ways:

Provide an upper bound on the engines.npm range in package.json. This example will prevent selecting npm >=10 when using older versions of Node.js:

{
  "engines": {
    "node": "18.2.x",
    "npm": "9.x"
  }
}

Upgrade to a newer Node.js that is compatible with the npm version. This example pins both engines to compatible major versions.

{
  "engines": {
    "node": "20.x",
    "npm": "10.x"
  }
}

Alternatively, remove the engines.npm directive completely to use the npm version associated with the selected Node.js version. This example will use the npm version that ships with Node.js.

{
  "engines": {
    "node": "18.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