【问题标题】:could not create react project无法创建反应项目
【发布时间】:2021-06-15 20:05:44
【问题描述】:

我正在尝试使用命令创建一个反应项目

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.

【问题讨论】:

  • 你使用的是什么版本的 Node 和 NPM?

标签: reactjs npm npx


【解决方案1】:

我一整天都在尝试做同样的事情,最后我不得不打开文档,上面提到你也可以使用创建 react 应用程序

npm init create-react-app **app_name**

它对我很有效。

这个依赖的事情让我很困扰。

【讨论】:

【解决方案2】:

我在使用 NPM 版本 7.20.0 时遇到了同样的问题。
只需安装旧版本的 NPM。
在终端运行:npm install npm@6.14.11 -g

【讨论】:

    【解决方案3】:

    似乎有一些特定版本的 NPM 会导致此问题。尝试更新到最新版本的 NPM。

    【讨论】:

      【解决方案4】:

      您可以尝试使用 npm update 更新 npm,看看是否可以解决问题,如果没有,您可以尝试这些步骤。

      如果您之前通过npm install -g create-react-app 全局安装了create-react-app,建议您使用npm uninstall -g create-react-appyarn 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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-09-04
        • 1970-01-01
        • 2022-07-30
        • 2020-10-15
        • 2021-12-17
        • 2019-07-31
        • 1970-01-01
        • 2021-05-30
        相关资源
        最近更新 更多