node.js - 如何在使用 yarn 安装 npm 依赖项时忽略不兼容的引擎 "node"错误?

标签 node.js npm npm-install yarnpkg

鉴于此 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 失败了:

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

看起来 yarn 在安装库 s3-streams@0.3.0 时遇到了问题,但我认为它会像 npm 那样安装所有依赖项。

最佳答案

您确实可以通过 --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.

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

$ 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

关于node.js - 如何在使用 yarn 安装 npm 依赖项时忽略不兼容的引擎 "node"错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45088031/

相关文章:

node.js - 安装Angular不支持的引擎,OSX

javascript - 函数到 es6 类基样式

node.js - Jade 内联条件

javascript - 在 Express JS 中设置 HTTPS

javascript - gulp:自动为请求添加版本号以防止浏览器缓存

node.js - npm 安装失败并出现错误

javascript - aws-lambda 找不到模块

Laravel 混合 "sh: 1: cross-env: not found error"

javascript - "Npm install --global"和 "--save"在一起?

node.js - 为什么 npm 在 package.json 中添加一些带下划线的属性