Node engine 8.x or 10.x in package.json

Javascriptnode.jsNpmpackage.jsonYarnpkg

Javascript Problem Overview


I tried to specify the node engine in a package.json to accept both 8 and 10 version.

I tried to type this:

"engines": {
  "node": "8.x|10.x"
},

But running yarn results in:

> The engine "node" is incompatible with this module. Expected version "8.x|10.x"

If I replace with:

"engines": {
  "node": "10.x"
},

... it works (i.e no error).

Is there a way to accept two versions of node engine in a package.json?

Javascript Solutions


Solution 1 - Javascript

See the documentation which includes examples.

Provide a space separated list of engines with greater/less than symbols.

{ 
  "engines" : { 
    "node" : ">=8.0.0 <11.0.0" 
  }
}

Solution 2 - Javascript

You just need the double pipe || instead of a single.

"engines": {
  "node": "^8 || ^10"
}

Would match either v8.x.x or v10.x.x but not v9.

You can read more about it here https://docs.npmjs.com/files/package.json#dependencies

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionrap-2-hView Question on Stackoverflow
Solution 1 - JavascriptQuentinView Answer on Stackoverflow
Solution 2 - JavascriptGabe MView Answer on Stackoverflow