npx create-react-app my-project
导致以下依赖错误:
npx版本:8.5.0
Installing template dependencies using npm...
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected] /cdn-cgi/l/email-protection
npm ERR! Found: [email protected] /cdn-cgi/l/email-protection
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/[email protected] /cdn-cgi/l/email-protection
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 start
在创建的目录中出现错误web-vitals
失踪于node-modules
.
尝试过的解决方案
Update
该问题已通过最新更新修复create-react-app
。现在它创建一个项目没有任何问题。
在这个问题暂时解决之前,您可以删除node_modules
文件夹和package-lock.json
。接下来,打开package.json
并改变
"react": "^18.0.0"
& "react-dom": "^18.0.0"
到早期版本,例如:
"react": "^17.0.2"
& "react-dom": "^17.0.2"
.
最后,你可以运行npm install
.
替代解决方案(首先尝试这个!):
建议的解决方案朱尼1998 https://github.com/facebook/create-react-app/issues/12269#issuecomment-1095746716):
- 删除两者
node_modules
and package-lock.json
- run
npm i web-vitals --save-dev
- run
npm install
然后你可以使用npm run build
and npm start
again
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)