无法解决依赖关系:npm 错误!来自uglifyjs-webpack-plugin@2.2.0的对等webpack@ "^4.0.0"



以下是我的错误细节:我的节点版本是16.13.0和npm8.12.1.

PS D:ShowCase> npm install
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: uglifyjs-webpack-plugin@2.2.0
npm ERR! Found: webpack@5.51.1
npm ERR! node_modules/webpack
npm ERR!   dev webpack@"^5.47.1" from the root project
npm ERR!   peer webpack@"4.x.x || 5.x.x" from @webpack-cli/configtest@1.0.4
npm ERR!   node_modules/@webpack-cli/configtest
npm ERR!     @webpack-cli/configtest@"^1.0.4" from webpack-cli@4.8.0
npm ERR!     node_modules/webpack-cli
npm ERR!       dev webpack-cli@"^4.7.2" from the root project
npm ERR!       3 more (@webpack-cli/configtest, @webpack-cli/info, @webpack-cli/serve)
npm ERR!   8 more (babel-loader, css-loader, ...)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer webpack@"^4.0.0" from uglifyjs-webpack-plugin@2.2.0
npm ERR! node_modules/uglifyjs-webpack-plugin
npm ERR!   dev uglifyjs-webpack-plugin@"^2.2.0" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: webpack@4.46.0
npm ERR! node_modules/webpack
npm ERR!   peer webpack@"^4.0.0" from uglifyjs-webpack-plugin@2.2.0
npm ERR!   node_modules/uglifyjs-webpack-plugin
npm ERR!     dev uglifyjs-webpack-plugin@"^2.2.0" 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.

如果有人遇到同样的问题,请告诉我。提前谢谢。

uglifyjs-webpack-plugin将与webpack4工作良好但是不能在Webpack 5下工作。因为这个插件不在Webpack 5中,你最好把Webpack从5降级到4。或者尝试其他插件,如babel-minify-webpack-pluginterser-webpack-plugin,以减少javascript,如果你想使用uglifyjs-webpack-plugin专门减少javascript代码。


您可以查看uglifyjs-webpack-plugin的最后一个稳定版本是3年前的,并且没有Webpack 5的文档开发支持。

我也遇到过类似的问题。尝试更新webpack,甚至安装yarn,但它似乎不起作用,此外,当我尝试安装新版本的webpack-cli时,它抛出了类似的错误。我所做的是在包上手动更改webpack-cli的版本。今天我把json升级到最新版本(5.1.4),我终于可以安装和运行其他所有东西了。

相关内容

  • 没有找到相关文章

最新更新