Even though engineStrict
is deprecated, you can still accomplish this behavior without needing to use an additional script to enforce a Node version in your project.
-
Add the
engines
property to yourpackage.json
file. For example:{ "name": "example", "version": "1.0.0", "engines": { "node": ">=14.0.0" } }
-
Create a
.npmrc
file in your project at the same level as yourpackage.json
. -
In the newly created
.npmrc
file, addengine-strict=true
.engine-strict=true
This will enforce the engines
you’ve defined when the user runs npm install
. I’ve created a simple example on GitHub for your reference.