使用 webpack 时 npm 安装错误,无法解决依赖关系

Cry*_*tal 11 node.js npm leaflet webpack webpack-2

错误如下:

> 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
Run Code Online (Sandbox Code Playgroud)

debug.log文件内容: 在此输入图像描述

包版本和系统

  • npm:7.6.3
  • 网络包:3.12.0
  • 系统:Ubuntu 20.04

我应该如何修复它?

Tro*_*ott 16

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