错误eslint@5.6.0:引擎“node”与此模块不兼容。尝试创建react应用程序时。

13

我正在尝试创建一个React应用程序,并在控制台中看到以下错误。

Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts...

yarn add v1.10.1
info No lockfile found.
[1/4]   Resolving packages...
warning react-scripts > eslint > file-entry-cache > flat-cache > circular-   json@0.3.3: CircularJSON is in maintenance only, flatted is its successor.
[2/4]   Fetching packages...
error eslint@5.6.0: The engine "node" is incompatible with this module.    Expected version "^6.14.0 || ^8.10.0 || >=9.10.0". Got "9.5.0"
error Found incompatible module
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this     command.

Aborting installation.
yarnpkg add --exact react react-dom react-scripts --cwd      /Volumes/server2/Desktop/JavaScript/birdcage has failed.

  Deleting generated file... package.json
  Deleting birdcage / from /Volumes/server2/Desktop/JavaScript
  Done.

我尝试过brew upgrade node,但好像没有用。 有什么方法可以修复这个问题将不胜感激。

11个回答

15

其中一个临时的解决方案是运行yarn install --ignore-engines


好建议!在哪里可以设置引擎标志?我在eslint.rc文件中没有设置,所以它一定是默认值。 - eagercoder

14

我遇到了同样的问题,请在create react app命令末尾添加"--use-npm"。

create-react-app 应用名 --use-npm


3

我也遇到了相同的问题,只需要这样做就能解决问题:

 npm install node@latest

1

我也遇到过同样的问题,尝试以下方法:

yarn config set ignore-engines true

1

尝试卸载yarn并通过npm安装它。

  1. npm i create-react-app -g
  2. create-react-app yourappname 确保已安装node!

0
假设已经安装了 nvm,请使用它来查看您正在使用的 node 版本,然后使用它切换到较新的版本。

0

我重新安装了Node并更新了Xcode开发工具。同时,在运行Mojave的计算机上重新安装了React。


0

你可以使用 nvm use <version> 命令切换版本,然后再次尝试。


0

当我使用npx和yarn将路由器插件添加到vue-cli时,我遇到了相同的问题。 在Python虚拟环境中,我已经将节点版本从8.x.x更新到16.x.x,并使用命令nvm use 16.x.x,但问题仍然存在..实际上,我是以root身份执行命令的..所以nvm仍然使用节点版本8.x.x ..

很长时间后,我意识到使用sudo命令是个问题,然后以普通用户身份执行了命令...

这个解决方案对我有效!!!


0

正如警告所说,我通过 nvm 更新了 node 到所需的版本。对我来说,拥有最新的 node lts 版本就足够了。

nvm install "lts/*" --reinstall-packages-from="$(nvm current)"

但即使升级了 node,yarn 仍然出现错误。

问题是 npm 仍然从先前 node 版本的旧 .bin 路径执行。nvm 还会在相应的本地 .bin 文件夹中为安装的 node 版本安装最新版本的 npm

接着我使用以下命令:

nvm install-latest-npm: 尝试升级到当前 node 版本上的最新工作版 npm

nvm install --latest-npm: 安装后,尝试升级到给定 node 版本上的最新工作版 npm

之后,它正常工作了。

参考: 如何使用 nvm 更改 npm 的版本?


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接