npm engines field — require specific Node.js version
Quick Answer
// package.json
{
"engines": {
"node": ">=20.0.0",
"npm": ">=9.0.0"
}
}
# By default this is advisory. To enforce it:
# .npmrc
engine-strict=true
When this happens
npm warn EBADENGINE Unsupported engine {
package: 'my-app@1.0.0',
required: { node: '>=20.0.0' },
current: { node: 'v18.12.0', npm: '8.19.2' }
}
The installed Node.js version does not satisfy the engines requirement in package.json.
Other causes & fixes
Enforce engines (blocks install on wrong version)
# .npmrc
engine-strict=true
# Now npm install will fail if Node.js version is incompatible
Use .nvmrc to pin the Node.js version
# .nvmrc
20.15.0
# Switch to the project version automatically
nvm use # reads .nvmrc
nvm install # installs if not present
Use Volta to manage Node.js per project
# Pin Node.js version with Volta (auto-switches)
volta pin node@20
volta pin npm@10
# This adds to package.json:
# "volta": { "node": "20.x.x", "npm": "10.x.x" }
Related