Specify Node, NPM Version to use
Goal
Require specific versions of node or npm in a Node.js project.
Effect
npm i
will throw errors if the versions do not match.
npm ERR! code EBADENGINE
npm ERR! engine Unsupported engine
npm ERR! engine Not compatible with your version of node/npm: name@0.0.1
npm ERR! notsup Not compatible with your version of node/npm: name@0.0.1
npm ERR! notsup Required: {"node":">=16.7.0","npm":">=7.20.3"}
npm ERR! notsup Actual: {"npm":"7.21.0","node":"v16.6.2"}
How
In package.json
set engines.node
or engines.npm
values.
// package.json{
"engines": {
"node": ">=0.10.3 <15",
"npm": "~1.0.20"
}
}// All semantic versions are valid, so 14.x also work.
In .npmrc
add engine-strict=true
value.
// .npmrcengine-strict=true// If set to true, then npm will stubbornly refuse to install (or even consider installing) any package that claims to not be compatible with the current Node.js version.
Note
engineStrict
is no longer supported. (Related Article)