reactjs - 无法创建 react 项目

标签 reactjs npm npx

我试图使用命令创建一个 react 项目

npx create-react-app chat-app
但我收到此错误。
Creating a new React app in /home/mikhil/react-tutorial/internshala-react-course/chat-app.

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

npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!  npm ERR! Found: @babel/core@undefined 
npm ERR! node_modules/@babel/core npm ERR!  
npm ERR! Could not resolve dependency: 
npm ERR! peer @babel/core@"^7.0.0-0" from @babel/preset-env@7.13.10 
npm ERR! node_modules/@babel/preset-env 
npm ERR!   @babel/preset-env@"^7.12.1" from @svgr/webpack@5.5.0 
npm ERR!   node_modules/@svgr/webpack 
npm ERR!     @svgr/webpack@"5.5.0" from react-scripts@4.0.3
npm ERR!     node_modules/react-scripts 
npm ERR!       react-scripts@"*" 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! See /home/mikhil/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in: 
npm ERR!     /home/mikhil/.npm/_logs/2021-03-18T11_58_50_255Z-debug.log

Aborting installation.   npm install --save --save-exact --loglevel
error react react-dom react-scripts cra-template has failed.

Deleting generated file... package.json 
Deleting chat-app/ from /home/mikhil/react-tutorial/internshala-react-course
Done.

最佳答案

您可以尝试使用 npm update 更新 npm看看是否能解决它,如果不能,你可以尝试这些步骤。
如果您以前安装过 create-react-app全局通过 npm install -g create-react-app ,建议您使用 npm uninstall -g create-react-app 卸载软件包或 yarn global remove create-react-app确保npx始终使用最新版本。
您还需要删除 chat-app 的剩余文件和文件夹。
一旦您在 /home/mikhil/react-tutorial/internshala-react-course目录并且您已经删除了全局安装,您可以尝试运行这些命令。

npx create-react-app my-app
cd my-app
npm start
Create React App - Getting Started

关于reactjs - 无法创建 react 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66690811/

相关文章:

reactjs - 如何在 React 或 React Native 上使用 useMutation 或 useQuery 作为钩子(Hook)?

ios - 在 React Native 中获取 ScrollView 的当前滚动位置

javascript - npx 是否寻找全局安装的包?

Next.js create-next-app 将不再工作

javascript - npx create-react-app 客户端给出此错误 "Cannot read properties of undefined (reading ' isServer')"

javascript - react native 导航器在大型应用程序中建模的最佳方式?

reactjs - react 原生相机胶卷 .heic 文件

npm - 有没有办法让 `npm pack` 递归地包含所有依赖包而不仅仅是基础包?为什么要这样做?

node.js - SPFX sharepoint Web 部件的 Node JS 和 npm 安装

npm - 当预发布版本是最新可用版本时,semver 中的插入符号 (^) 是否与预发布匹配?