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

8.5k Views Asked by At

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: [email protected]
npm ERR! notsup Not compatible with your version of node/npm: [email protected]
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 [email protected]
npm ERR! code EBADENGINE
npm ERR! engine Unsupported engine
npm ERR! engine Not compatible with your version of node/npm: [email protected]
npm ERR! notsup Not compatible with your version of node/npm: [email protected]
npm ERR! notsup Required: {"npm":"8.8.0"}
npm ERR! notsup Actual:   {"npm":"8.7.0"}

When updating the npm version with npm install [email protected] 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?

2

There are 2 best solutions below

0
On BEST ANSWER

Eventually it turned out npm could only be updated globally, thus using npm install -g [email protected], instead of npm install [email protected]

0
On

Why don't you just remove deadlock by removing .npmrc file or

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

then install your desired npm package then bring your changes back. also you can use nvm for better and also backward version changes