如何忽略不兼容的发动机“节点”错误安装 npm 依赖与纱线?

鉴于这种 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"
}
}

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

$ npm install


added 27 packages in 1.844s

然而,这种说法失败了:

$ yarn install
yarn install v0.24.5
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
error s3-streams@0.3.0: 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.

看起来纱线在安装程序库 s3-streams@0.3.0时遇到了麻烦,但是我认为它会像 npm一样退回来安装所有的依赖项。

101916 次浏览

You can indeed ignore such errors via --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

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, you can do "create-react-app my-app"

--ignore-engines doesn't work with the yarn start command

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

check your node version with:

node -v

check your npm version with:

npm -v

Open package.json and make sure the values you got from running the two commands above match with the versions of node and npm in the engines object.

OR

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

add --ignore-engines to remove the errors

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


If you run into this problem, it might be because you have several versions of node on your system.

For example, you might have run some command that installs an uptodate version of node in one place, but be running a different version of node because it's directory is ahead of the other one in $PATH.

So it might be a good idea to run

which -a node

If the nvm version is out-of-date, you could update it, e.g. to a particular version: nvm install 15.4.0