Javascript package.json 中的节点引擎 8.x 或 10.x

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/51596127/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 04:52:15  来源:igfitidea点击:

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

javascriptnode.jsnpmpackage.jsonyarnpkg

提问by rap-2-h

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

我试图在 package.json 中指定节点引擎以同时接受810版本。

I tried to type this:

我试着输入这个:

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

But running yarnresults in:

但是运行yarn结果是:

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

引擎“节点”与此模块不兼容。预期版本“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?

有没有办法在一个中接受两个版本的节点引擎package.json

回答by Quentin

See the documentationwhich includes examples.

请参阅包含示例的文档

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

提供一个空格分隔的引擎列表,其中包含大于/小于符号。

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

回答by Gabe M

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 notv9.

将匹配 v8.xx 或 v10.xx 但匹配v9。

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

你可以在这里阅读更多关于它的信息https://docs.npmjs.com/files/package.json#dependencies

回答by FoneBay

It's working in my case.

它在我的情况下工作。

"private": true,
  "engines": {
    "node": "8"
      }
}