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

10
以下是错误信息:
> npm install
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! Found: webpack@3.12.0
npm ERR! node_modules/webpack
npm ERR!   dev webpack@"^3.5.6" from the root project
npm ERR!   peer webpack@"2 || 3 || 4" from _babel-loader@7.1.5@babel-loader@7.1.5
npm ERR!   node_modules/_babel-loader@7.1.5@babel-loader
npm ERR!   5 more (_html-webpack-plugin@2.30.1@html-webpack-plugin, ...)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer webpack@"^2.0.0" from _strip-pragma-loader@1.0.0@strip-pragma-loader@1.0.0
npm ERR! node_modules/_strip-pragma-loader@1.0.0@strip-pragma-loader
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/agou-ops/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/agou-ops/.npm/_logs/2021-04-12T02_49_11_062Z-debug.log

debug.log文件内容: 在这里输入图片描述

包版本和系统:

  • npm:7.6.3
  • webpack:3.12.0
  • 系统:Ubuntu 20.04

我该如何修复它?

4个回答

15

npm@7 比以前的版本有更严格的依赖关系解析。如果您可以更新根项目中的 webpack 版本,则可能会解决问题。另一个简单快捷的尝试方法是使用 npm install --legacy-peer-deps 命令。


如果还不起作用,请尝试使用--force选项。也就是说,运行npm install --force命令。这对我很有效。 - Fadils

0

我遇到了同样的问题。

如果您没有使用相关的软件包,请尝试使用--force命令运行。

例如:

npm install --verbose --force

0

针对 npm v7+ 版本。这是由于 package.json 文件中提到的条目缺少依赖项所致。

使用以下命令:

npm i --force

或者

npm i --legacy-peer-deps

来覆盖对等依赖关系。 在此处得到答案


-1

通过以下命令将npm降级到较低版本:

npm install npm@6

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