繁体   English   中英

创建反应应用程序抛出错误“无法解析依赖树”和“修复上游依赖冲突”

[英]Create react app throwing errors 'unable to resolve dependency tree' and 'fix upstream dependency conflict'

我一直在尝试使用 create react app 但是当我 go 在终端中创建它时我收到了这个错误。

Installing template dependencies using npm...
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: test3@0.1.0
npm ERR! Found: react@18.0.0
npm ERR! node_modules/react
npm ERR!   react@"^18.0.0" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer react@"<18.0.0" from @testing-library/react@12.1.5
npm ERR! node_modules/@testing-library/react
npm ERR!   @testing-library/react@"^12.0.0" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR! 
npm ERR! See /Users/chrisheibel/.npm/eresolve-report.txt for a full report.

npm ERR!`

我试过使用--legacy-peer-deps--force但没有成功。 它将创建应用程序,但 npm 启动不起作用。 创建它后,我尝试安装/更新 npm 并再次节点,但没有成功。 我还在我的计算机上全局卸载了 node 和 npm 并重新安装但没有运气,以及将创建的应用程序中的 react 和 react-dom 转换为版本 17 而不是 18 但在那里没有运气。

我对此有点不知所措,因为 create react app 以前一直在我的电脑上运行。 但也许你们可能知道我是否在这里遗漏了什么,这就是为什么我无法运行 npm start/ 出现所有这些错误的原因。

错误消息告诉您问题出在哪里。 重要的部分是:

Found: react@18.0.0

peer react@"<18.0.0" from @testing-library/react@12.1.5

所以@testing-library/react@12.1.5只与 react <18 兼容并且你添加了 react 18,这打破了这个规则。 @testing-library/react升级到兼容版本或将 react 降级到 < 18。

@testing-library/react的最新版本是 13。所以你应该有类似的东西

"@testing-library/react": "^13.0.0"

在你的 package.json

我会检查你的 create-react-app 版本

create-react-app --version

我的说 5.0.0。

文档说卸载 create-react-app 并使用 npx 运行它。 使用 npx 运行将安装最新版本:

npm uninstall -g create-react-app
npx create-react-app your-app-name

当我今天运行 create-react-app 时,我得到了一个 React v18 应用程序。 在某些情况下,我不得不将其降级到 v17。 我这样做如下:

npm uninstall react react-dom
npm install react@!7 react-dom@17

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM