node.js 如何在使用纱线安装 npm 依赖项时忽略不兼容的引擎“节点”错误?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45088031/
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-09-02 18:21:58  来源:igfitidea点击:

How to ignore incompatible engine "node" error on installing npm dependencies with yarn?

node.jsnpmnpm-installyarnpkg

提问by k0pernikus

Given this package.json:

鉴于此package.json

{
  "name": "yarn-install-fail",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {},
  "author": "",
  "license": "ISC",
  "dependencies": {
    "aws-sdk": "2.x.x",
    "s3-streams": "^0.3.0"
  }
}

I can install the dependencies successfully via npm:

我可以通过 npm 成功安装依赖项:

$ npm install

added 27 packages in 1.844s

Yet yarn fails:

然而纱线失败了:

$ yarn install
yarn install v0.24.5
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
error [email protected]: The engine "node" is incompatible with this module. Expected version "^1.2.0".
error Found incompatible module
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

It appears yarn has trouble installing the library [email protected], yet I assumed it would fallback to install all the dependencies anyway like npmwould.

看起来 yarn 安装库有问题[email protected],但我认为它会像那样安装所有依赖项npm

回答by k0pernikus

You can indeed ignore such errors via --ignore-engines:

您确实可以通过--ignore-engines忽略此类错误:

$ yarn install --ignore-engines
yarn install v0.24.5
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
Done in 1.41s.

This is also documented in the command's help:

这也记录在命令的帮助中:

$ yarn help | grep -- --ignore
    --ignore-scripts                  don't run lifecycle scripts
    --ignore-platform                 ignore platform checks
    --ignore-engines                  ignore engines check
    --ignore-optional                 ignore optional dependencies

回答by Luke Phillips

"yarn config set ignore-engines true" Is a one time fix for the "the engine node is incompatible with this module" problem. Once that is completed then you can do "create-react-app my-app"

“yarn config set ignore-engines true”是对“引擎节点与此模块不兼容”问题的一次性修复。完成后,您可以执行“create-react-app my-app”

回答by Mahendra Pratap

--ignore-enginesdoesn't work with the yarn startcommand

--ignore-engines不适用于该yarn start命令

So there are two solutions for that to get rid of it.

因此,有两种解决方案可以摆脱它。

check your node version with:

使用以下命令检查您的节点版本:

node -v

节点 -v

check your npm version with:

使用以下命令检查您的 npm 版本:

npm -v

npm -v

Open package.json and make sure the values you got from running the two commands above match with the versions of nodeand npmin the enginesobject.

开放的package.json,并确保你从的版本上运行的上述比赛的两个命令得到了价值node,并npmengines对象。

OR

或者

You can simply remove enginesfrom the package.json file otherwise it will always check the version to match.

您可以简单地engines从 package.json 文件中删除,否则它将始终检查版本以匹配。