node.jsnpmversion-controlpackage.json.npmrc

Updating NPM Requires New Version of NPM(deadlock) With engines Requirement in package.json


When requiring a strict version of npm in package.json with an .npmrc file it gives an error when running npm ci as expected, but does not allow the npm version to be updated.

package.json

"engines": {
    "npm": "8.7.0"
}

.npmrc

engine-strict=true

error (expected)

$ npm ci
npm ERR! code EBADENGINE
npm ERR! engine Unsupported engine
npm ERR! engine Not compatible with your version of node/npm: psw-portal@1.0.0
npm ERR! notsup Not compatible with your version of node/npm: psw-portal@1.0.0
npm ERR! notsup Required: {"npm":"8.8.0"}
npm ERR! notsup Actual:   {"npm":"8.7.0"}

error when attempting to update npm (unexpected)

$npm install npm@8.8.0
npm ERR! code EBADENGINE
npm ERR! engine Unsupported engine
npm ERR! engine Not compatible with your version of node/npm: psw-portal@1.0.0
npm ERR! notsup Not compatible with your version of node/npm: psw-portal@1.0.0
npm ERR! notsup Required: {"npm":"8.8.0"}
npm ERR! notsup Actual:   {"npm":"8.7.0"}

When updating the npm version with npm install npm@8.8.0 the same error is thrown. Installing the new versions requires the new version, resulting in a deadlock...

What would be the appropriate way of enforcing an npm version in an Node.js project without this deadlock?


Solution

  • Eventually it turned out npm could only be updated globally, thus using npm install -g npm@8.8.0, instead of npm install npm@8.8.0