我正在尝试使用 React v19.0.0(最新)创建一个 React 应用程序,但在安装软件包时收到错误。我将逐步解释我所做的事情。
npm install --save-exact @types/react@^19.0.0 @types/react-dom@^19.0.0
10.8.2
npx create-react-app . --template typescript
Installing template dependencies using npm...
npm error code ERESOLVE
npm error ERESOLVE unable to resolve dependency tree
npm error
npm error While resolving: [email protected]
npm error Found: [email protected]
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/[email protected]
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:\Users\Jason.Susanto\AppData\Local\npm-cache\_logs\2025-01-22T03_35_27_382Z-eresolve-report.txt
npm error A complete log of this run can be found in: C:\Users\Jason.Susanto\AppData\Local\npm-cache\_logs\2025-01-22T03_35_27_382Z-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 @types/jest@^27.0.1 @types/node@^16.7.13 @types/react@^18.0.0 @types/react-dom@^18.0.0 typescript@^4.4.2 web-vitals@^2.1.0` failed
这是日志文件内容:
# npm resolution error report
While resolving: [email protected]
Found: [email protected]
node_modules/react
react@"^19.0.0" from the root project
Could not resolve dependency:
peer react@"^18.0.0" from @testing-library/[email protected]
node_modules/@testing-library/react
@testing-library/react@"^13.0.0" from the root project
Fix the upstream dependency conflict, or retry
this command with --force or --legacy-peer-deps
to accept an incorrect (and potentially broken) dependency resolution.
最后,在升级到19.0.0版本之前,我曾经使用React 18.2.0版本
有什么办法可以解决这个问题吗?
谢谢!
您可以使用 --force 运行安装命令,但最安全的方法是降级回 18,直到所有依赖项都升级到 19。