npm安装无法解析依赖树

8

我从Creative Tim网站购买了高级仪表盘主题,但是当我尝试操作它时,无法安装软件包。运行npm install命令时,出现以下错误:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: argon-dashboard-pro-react@1.2.0
npm ERR! Found: react@17.0.1
npm ERR! node_modules/react
npm ERR!   react@"17.0.1" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^16.3.0" from react-bootstrap-table-next@4.0.3
npm ERR! node_modules/react-bootstrap-table-next
npm ERR!   react-bootstrap-table-next@"4.0.3" 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 C:\Users\acer\AppData\Local\npm-cache\eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\acer\AppData\Local\npm-cache\_logs\2021-02-08T12_06_48_302Z-debug.log


如何修复这个错误。我已经尝试使用--legacy-peer-deps和--force命令,但仍然无法解决问题。

删除 node_models 文件夹和 packge-lock.json,然后运行 npm i。 - Roy.B
这里有关于ReactJS无法解决依赖树的问题的答案:https://dev59.com/LFIG5IYBdhLWcg3whQaH - Jay Surya
你使用的是哪个版本的 node-sass 和 Node.js? - Marios Nikolaou
4个回答

7

我曾经遇到过这个问题,以下是两种解决方法:

  1. npm install --legacy-peer-deps

    如果你好奇这个命令的作用是什么? 这个命令会带有 --legacy 标志进行安装,它会忽略所有的 peer 依赖项,就像 npm 4 到 6 版本一样。

  2. 这个错误来自 npm 7.x 版本。因此,另一个解决方法是降级到 npm 6.x。

参考:了解更多信息


4
我遇到了类似的错误,添加--legacy-peer-deps解决了问题。运行以下命令:npm install --legacy-peer-deps。关于'--legacy-peer-deps'的更多信息可以在这里阅读。

2
这是一个黑客修复还是有其他解决问题的方法? - v3nt

2
尝试使用以下命令:

npm cache clean --force

npm install --legacy-peer-deps


1
使用force/legacy --legacy-peer-deps是为了接受不正确的对等依赖项,最好弄清楚您尝试安装的软件包的对等依赖项,查看其对等依赖项版本,然后更新您的项目依赖项以匹配软件包的对等依赖项。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接