Skip to content

Detect when version is incompatible with engines field in package.jsonΒ #29249

@broofa

Description

@broofa

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.moduleIssues and PRs related to the module subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions