简体   繁体   English

无法使用 create react app 创建 React 项目

[英]Unable to create React project using create react app

So I'm trying to learn React, followed the instruction on https://reactjs.org/docs/create-a-new-react-app.html .所以我正在尝试学习 React,按照https://reactjs.org/docs/create-a-new-react-app.html上的说明进行操作。 Specifically, I'm using Create React App, and happened to bump into an error:具体来说,我正在使用 Create React App,但碰巧遇到了一个错误:

Installing template dependencies using npm...
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: test-react@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!

From what I'm seeing here, the Testing library required that the installed React version be less than 18.0.0, but Create React App just automatically install the latest React version, leading to the error.从我在这里看到的情况来看,测试库要求安装的 React 版本低于 18.0.0,但 Create React App 只是自动安装最新的 React 版本,从而导致错误。

How do I resolve this?我该如何解决这个问题? As said earlier, I'm a complete newbie, so any help is much appreciated.如前所述,我是一个完全的新手,所以非常感谢任何帮助。

Until this is fixed for now you can delete the node_modules folder and package-lock.json .在暂时解决此问题之前,您可以删除node_modules文件夹和package-lock.json

Next, open package.json and change "react": "^18.0.0" & "react-dom": "^18.0.0" to an earlier version eg "react": "^17.0.2" & "react-dom": "^17.0.2" .接下来,打开package.json并将"react": "^18.0.0" & "react-dom": "^18.0.0"更改为早期版本,例如"react": "^17.0.2" & "react-dom": "^17.0.2"

Finally, can run npm install最后,可以运行npm install

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

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