首页 > 解决方案 > Yarn 错误地报告不兼容的节点版本失败

问题描述

我正在尝试yarn在我的项目中运行命令,但它失败了,报告了不兼容的节点版本。

奇怪的是,我的版本nodeis 12.7.0,而不是13.0.0-nightly2019072543e5478e2fYarn 报告的那样。

这是怎么回事?

注意:我使用的是 Ubuntu 18.04 LTS,它的 Node 版本已经过时,但我使用 NVM 将其更新为 12.7.0。

命令输出

$ yarn

yarn install v1.17.3
warning You are using Node "13.0.0-nightly2019072543e5478e2f" which is not supported and may encounter bugs or unexpected behavior. Yarn supports the following semver range: "^4.8.0 || ^5.7.0 || ^6.2.2 || >=8.0.0"
[1/4] Resolving packages...
[2/4] Fetching packages...
error xmlbuilder@9.0.7: The engine "node" is incompatible with this module. Expected version ">=4.0". Got "13.0.0-nightly2019072543e5478e2f"
error Found incompatible module.

$ node --version

v12.7.0

$ nvm list

        v12.6.0
->      v12.7.0
         system
default -> node (-> v12.7.0)
node -> stable (-> v12.7.0) (default)
stable -> 12.7 (-> v12.7.0) (default)
iojs -> N/A (default)
unstable -> N/A (default)
lts/* -> lts/dubnium (-> N/A)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.16.0 (-> N/A)
lts/dubnium -> v10.16.0 (-> N/A)

标签: node.jsubuntuyarnpkgubuntu-18.04

解决方案


我也看到了这个问题,输出如下:

The engine "node" is incompatible with this module. Expected version "^12.1.0". Got "14.18.0"

在我的package.json中,我发现: "engines": { "node": "^12.1.0", "npm": ">= 5" }

我使用npm install -g n. 请注意,n 仅适用于 Linux/MacOS。Windows 可以使用 NVM 来达到同样的目的。然后我运行n 12.1.0并安装了 Node 版本 12.1.0,Yarn 现在很高兴。

https://blog.logrocket.com/switching-between-node-versions-during-development/ - 有关更改节点版本的说明。


推荐阅读