【React】执行npx create-react-app react-demo报错

Installing template dependencies using npm...
npm error code ERESOLVE
npm error ERESOLVE unable to resolve dependency tree
npm error
npm error While resolving: react-demo@0.1.0
npm error Found: react@19.0.0
npm error node_modules/react
npm error   react@"^19.0.0" from the root project
npm error
npm error Could not resolve dependency:
npm error peer react@"^18.0.0" from @testing-library/react@13.4.0
npm error node_modules/@testing-library/react
npm error   @testing-library/react@"^13.0.0" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry
npm error this command with --force or --legacy-peer-deps
npm error to accept an incorrect (and potentially broken) dependency resolution.
npm error
npm error
npm error For a full report see:
npm error C:\DDisk\Develop\nodejs\node_cache\_logs\2024-12-30T13_24_02_982Z-eresolve-report.txt
npm error A complete log of this run can be found in: C:\DDisk\Develop\nodejs\node_cache\_logs\2024-12-30T13_24_02_982Z-debug-0.log
`npm install --no-audit --save @testing-library/jest-dom@^5.14.1 @testing-library/react@^13.0.0 @testing-library/user-event@^13.2.1 web-vitals@^2.1.0` failed

如果你不介意使用 React 18,可以将 React 版本降级到与 @testing-library/react 兼容的版本。

修改 package.json 文件中的 React 版本:
“dependencies”: {
“react”: “^18.0.0”,
“react-dom”: “^18.0.0”,
// …其他依赖
}
然后重新安装依赖,在项目目录下执行:

npm install

执行npm start,再次报错:

Failed to compile.

Module not found: Error: Can't resolve 'web-vitals' in 'C:\DDisk\CodingSpace\FrontEndWorkspace\ReactWorkSpace\react-demo\src'
ERROR in ./src/reportWebVitals.js 5:4-24
Module not found: Error: Can't resolve 'web-vitals' in 'C:\DDisk\CodingSpace\FrontEndWorkspace\ReactWorkSpace\react-demo\src'

webpack compiled with 1 error

执行npm install web-vitals
重新执行npm start,正常运行了。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值