【问题标题】:Cannot create React app as NPM is "unable to resolve dependency tree"无法创建 React 应用程序,因为 NPM “无法解析依赖树”
【发布时间】:2021-08-23 05:39:00
【问题描述】:

我正在尝试创建一个 React 应用程序。以下是 Node 和 NPM 的版本:

C:\React>node -v
v15.2.0

C:\React>npm -v
7.0.8

当我运行命令创建 React 应用程序时,出现以下消息:

C:\React>npx create-react-app my-app

Creating a new React app in C:\React\my-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@7.12.3
npm ERR! node_modules/@babel/core
npm ERR!   @babel/core@"7.12.3" from react-scripts@4.0.3
npm ERR!   node_modules/react-scripts
npm ERR!     react-scripts@"*" from the root project
npm ERR!   @babel/core@"^7.12.3" 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!   9 more (babel-jest, babel-loader, ...)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer @babel/core@"^7.13.0" from @babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining@7.14.5
npm ERR! node_modules/@babel/preset-env/node_modules/@babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining
npm ERR!   @babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining@"^7.14.5" from @babel/preset-env@7.15.0
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!
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.

【问题讨论】:

  • 使用--legacy-peer-deps 就像错误消息提示的那样。将其归咎于 NPM v7 对对等依赖项的错误处理。

标签: reactjs npm create-react-app


【解决方案1】:

这是因为对等依赖项不匹配。我之前通过以下方式解决了这个问题:

npm install -g npm@latest

接着是:

npx create-react-app my-app

【讨论】:

    猜你喜欢
    • 2021-05-07
    • 2021-05-12
    • 1970-01-01
    • 2021-08-11
    • 1970-01-01
    • 2022-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多