npm install 无法解析依赖树

Posted

技术标签:

【中文标题】npm install 无法解析依赖树【英文标题】:npm install unable to resolve dependency tree 【发布时间】:2021-05-12 01:17:42 【问题描述】:

所以我从 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 这里回答https://***.com/questions/64718633/unable-to-resolve-dependency-tree-reactjs 你有什么node-sass 和节点版本? 【参考方案1】:

试试这个命令

npm cache clean --force

npm install --legacy-peer-deps

【讨论】:

【参考方案2】:

我遇到了这个问题,两种解决方案中的任何一种都对我有用。它们是:

    npm install --legacy-peer-deps

    如果您好奇它的作用是什么? 软件包将使用 --legacy 标志安装。该命令忽略所有 安装时的对等依赖项,以 npm 版本 4 的样式通过 第 6 版。

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

参考:Refer this for more info

【讨论】:

【参考方案3】:

我遇到了类似的错误,添加 --legacy-peer-deps 为我解决了这个问题。 npm install --legacy-peer-deps.

阅读更多关于“--legacy-peer-deps”here的信息。

【讨论】:

这是 hack 修复还是有解决问题的方法?

以上是关于npm install 无法解析依赖树的主要内容,如果未能解决你的问题,请参考以下文章

创建离子应用程序时无法解析依赖树

由于 ERESOLVE 无法解析依赖关系树,因此无法安装软件包 Pinia

npm install xxxx --legacy-peer-deps命令是什么?

使用 webpack 时出现 npm 安装错误,无法解析依赖项

npm install react-native-paper 期间的问题

React Native:npm链接本地依赖,无法解析模块