尝试使用React v19.0.0创建React应用程序但出现错误

问题描述 投票:0回答:1

我正在尝试使用 React v19.0.0(最新)创建一个 React 应用程序,但在安装软件包时收到错误。我将逐步解释我所做的事情。

  1. 通过运行命令升级react版本:
    npm install --save-exact @types/react@^19.0.0 @types/react-dom@^19.0.0
  2. 我的 npm 和 npx 版本是
    10.8.2
  3. 我在目录中创建一个文件夹,并在 VS Code 的终端中运行以下命令:
    npx create-react-app . --template typescript
  4. 运行此命令后,我收到此错误:
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版本

有什么办法可以解决这个问题吗?

谢谢!

reactjs node.js npm npx
1个回答
0
投票

您可以使用 --force 运行安装命令,但最安全的方法是降级回 18,直到所有依赖项都升级到 19。

© www.soinside.com 2019 - 2024. All rights reserved.