-
-
Notifications
You must be signed in to change notification settings - Fork 34.4k
Description
Is your feature request related to a problem? Please describe.
Currently there is no standard way for the author of an app to specify which versions of node are expected/required. Author's are left to their own devices for ways to enforce this.
Describe the solution you'd like
The [hopefully] obvious approach to this is to leverage the engines field in package.json. It already serves much the same purpose for NPM. Node, however, ignores this field entirely.
Node should inspect the applicable package.json file (the same file it already looks to for main and exports fields) to see if a engines.node version is defined. If so, it should apply the standard semver semantics to determine if the current version is incompatible with the engines version. If so, it should throw Error('Invalid node version. Current version is ${process.version}, but ${package.json path} engines.node requires ${package.json engines.node}.')
While this won't be catchable via try-catch (error will occur outside context of user script), it should be trappable via process.on('uncaughtException').
Describe alternatives you've considered
The runtime-engine-check module provides similar behavior
Edit: Some supporting material:
- Heroku uses engines.node
- Firebase uses engines.node
- SO question (and answer) with ad-hoc code for this
- ... and, fwiw, the Reddit thread discussing nvm version declaration and updating that prompted this report.