$ npm i
npm ERR! code ERESOLVE
# 不能解决依赖关系
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: html-webpack-plugin@5.5.0
npm ERR! Found: webpack@4.46.0
...
# 不能解决依赖关系
npm ERR! Could not resolve dependency:
npm ERR! peer webpack@"^5.20.0" from html-webpack-plugin@5.5.0
...
# 修复上游依赖冲突或重试
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 版本冲突引发中断安装过程,因为依赖冲突导致不能下载依赖包。
$ node -v
v16.19.1
$ npm -v
8.19.3
node与 npm 版本对应关系 nodejs.org/zh-cn/downl…
npm V7之前的版本遇到依赖冲突会忽视依赖冲突,继续进行安装。npm V7版本开始不会自动自动忽略,需用户手动输入命令。
可通过两个命令解决此问题
# 无视冲突,强制获取远端 npm 库资源,覆盖之前。
--force
# 忽视依赖冲突,继续安装,不覆盖之前。
--legacy-peer-deps
通过添加--legacy-peer-deps参数来绕过peerDependency自动安装,告知 NPM 忽略项目中引入的 各个modules 之间相同modules但不同版本的问题并继续安装,保证各个引入的依赖之间对自身所使用的不同版本modules共存。
$ npm i --legacy-peer-deps
npm WARN deprecated natives@1.1.6: This module relies on Node.js's internals and will break at some point. Do not use it, and update to graceful-fs@4.x.
added 297 packages, removed 139 packages, and changed 60 packages in 21s
130 packages are looking for funding
run `npm fund` for details