请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

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

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

正在回答 回答被采纳积分+3

插入代码

2回答

阿莱克斯刘 2024-12-22 01:05:21
使用 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 回复 有任何疑惑可以回复我~
  • 提问者 gyy_ #1
    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 13:43:40
qq_慕桂英6324852 2024-12-21 12:39:41

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

0 回复 有任何疑惑可以回复我~
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号