npm ERR! Conflicting peer dependency: [email protected] 版本冲突

npm ERR! Conflicting peer dependency: [email protected]

webpack版本问题
今天在重新安装node_modules时,遇到了如下错误:

$ npm install
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/webpack
npm ERR!   webpack@"^5.75.0" from the root project
npm ERR!   peer webpack@"^4.0.0" from [email protected]
npm ERR!   node_modules/css-loader
npm ERR!     css-loader@"^6.7.3" from the root project
npm ERR!   7 more (html-webpack-plugin, istanbul-instrumenter-loader, ...)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! babel-loader@"^9.1.2" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: [email protected]
npm ERR! node_modules/webpack
npm ERR!   peer webpack@">=5" from [email protected]
npm ERR!   node_modules/babel-loader
npm ERR!     babel-loader@"^9.1.2" 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\admin\AppData\Local\npm-cache\eresolve-report.txt for a fu                                 ll report.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\admin\AppData\Local\npm-cache\_logs\2023-02-08T03_26_58_05                                 6Z-debug-0.log

解决方案
运行以下命令:

npm install --save-dev html-webpack-plugin --legacy-peer-deps
$ npm install --save-dev html-webpack-plugin --legacy-peer-deps
npm WARN idealTree Removing dependencies.html-webpack-plugin in favor of devDepe                                 ndencies.html-webpack-plugin
npm WARN deprecated [email protected]: Please see https://github.com/lydell/urix#deprec                                 ated
npm WARN deprecated [email protected]: See https://github.com/lydell/source-m                                 ap-url#deprecated
npm WARN deprecated [email protected]: See https://github.com/lydell/sour                                 ce-map-resolve#deprecated
npm WARN deprecated [email protected]: https://github.com/lydell/resolve-url#dep                                 recated
npm WARN deprecated [email protected]: 0.x is no longer supported. Please upgra                                 de to 3.x or higher.
npm WARN deprecated [email protected]: 1.x is no longer supported. Please upgrad                                 e to 4.x or higher.
npm WARN deprecated [email protected]: CircularJSON is in maintenance only, fl                                 atted is its successor.
npm WARN deprecated [email protected]: Chokidar 2 does not receive security updates                                  since 2019. Upgrade to chokidar 3 with 15x fewer dependencies
npm WARN deprecated [email protected]: 3.x is no longer supported. Please upgrade to                                  6.x or higher.
npm WARN deprecated [email protected]: core-js@<3.23.3 is no longer maintained and                                  not recommended for usage due to the number of issues. Because of the V8 engine                                  whims, feature detection in old core-js versions could cause a slowdown up to 10                                 0x even if nothing is polyfilled. Some versions have web compatibility issues. P                                 lease, upgrade your dependencies to the actual version of core-js.

added 988 packages in 1m

如果有patch补丁的,可以再次运行npm install,发现补丁已经被打进去了:

$ npm install

> [email protected] postinstall
> patch-package

patch-package 6.5.1
Applying patches...
[email protected] ✔

added 4 packages, removed 2 packages, and changed 1 package in 6s

你可能感兴趣的:(npm,webpack,前端)