npm / cli

the package manager for JavaScript
https://docs.npmjs.com/cli/
Other
8.52k stars 3.19k forks source link

[BUG] Presence of devEngines in package.json disables engine-strict checks #7888

Closed maarten-t closed 2 weeks ago

maarten-t commented 3 weeks ago

Is there an existing issue for this?

This issue exists in the latest npm version

Current Behavior

When package.json contains the new devEngines key, the checks from the engines fields are disabled. Running npm install --engine-strict will happily install even when using incompatible node or npm versions w.r.t. engines.

This behavior is unexpected. According to the documentation the devEngines serves a different purpose from engines. For this reason they shouldn't interact in this way.

This should especially be the case if the contents of these sections don't overlap, e.g. when engines prescribes a specific node version and devEngines prescribes an npm version. However the mere presence of devEngines disables all engines checks, even if empty.

Currently, the engines field combined with the engine-strict is the only reliable way to enforce correct engine versions. Older npm versions don't support devEngines yet. If devEngines disables the older mechanism, we would need to duplicate the constraints from engines in devEngines until devEngines support is fully adopted.

Expected Behavior

npm install --engine-strict should perform the engines constraint checks from engines (as well as devEngines) value in package.json. Whenever the engines don't match the specified version(s), it should exit with an error.

Steps To Reproduce

  1. In an empty directory

  2. Create the following package.json file

    {
    "name": "reproduce-engine-strict-bug",
    "engines": {
    "node": "999999"
    },
    "devEngines": {}
    }
  3. Run npm install --engine-strict

  4. Notice how npm exits without an error, despite the node version being lower than 999999.

  5. Removing the devEngines will correctly result in npm error code EBADENGINE

Environment