react 19出之后create-react-app报错了

来源:2-2 【环境搭建】开始我们的第一个React项目

gyy_

2024-12-19

Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts with cra-template…

added 1320 packages in 19s

256 packages are looking for funding
run npm fund for details

Initialized a git repository.

Installing template dependencies using npm…
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: my-app@0.1.0
npm ERR! Found: react@19.0.0
npm ERR! node_modules/react
npm ERR! react@"^19.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@13.4.0
npm ERR! node_modules/@testing-library/react
npm ERR! @testing-library/react@"^13.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!
npm ERR!
npm ERR! For a full report see:
npm ERR! /home/liaozhuodi/.npm/_logs/2024-12-19T05_07_49_701Z-eresolve-report.txt

npm ERR! A complete log of this run can be found in:
npm ERR! /home/liaozhuodi/.npm/_logs/2024-12-19T05_07_49_701Z-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

写回答

2回答

阿莱克斯刘

2024-12-22

使用 Create React App 创建一个 React 18 项目非常简单。以下是步骤:

1. 确保你已安装了 Node.js 和 npm。你可以在终端中运行 `node -v` 和 `npm -v` 来检查。

2. 打开终端,运行以下命令来全局安装 Create React App:
   npx create-react-app my-react-app

3. 进入项目目录
   cd my-react-app

4. 安装 React 18:
   npm install react@18 react-dom@18

5. 启动开发服务器:
   npm start

这样,你就可以在浏览器中访问 `http://localhost:3000` 来查看你的 React 18 项目了。希望这能帮到你!如果还有其他问题,尽管告诉我。
0
1
gyy_
npx这个开魔法上网能正确执行,然后按照步骤3,4安装了React 18 但是npm start不起来,会有报错: Compiled with problems: × ERROR in ./src/index.tsx 7:0-24 Module not found: Error: Can't resolve './App' in '/2T/big-git-repos/test-robot/src' ERROR in ./src/index.tsx 8:0-48 Module not found: Error: Can't resolve './reportWebVitals' in '/2T/big-git-repos/test-robot/src' 或者是这样的报错: Failed to compile. Module not found: Error: Can't resolve 'web-vitals' in '/2T/big-git-repos/my-react-app/src' ERROR in ./src/reportWebVitals.js 5:4-24 Module not found: Error: Can't resolve 'web-vitals' in '/2T/big-git-repos/my-react-app/src' webpack compiled with 1 error
2025-01-02
共1条回复

qq_慕桂英6324852

2024-12-21

我也是这样  你先进入项目  把一些测试文件删掉  看看项目缺什么 你在 npm i 下载一下

0
0

React18 系统精讲 结合TS打造旅游电商平台

React18 精讲 + 结合 TS 实战 + 热门业务开发,获取必备技能

1993 学习 · 1015 问题

查看课程