记一个npm安装依赖报错

npm install 

F:\tewst1111>npm i
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
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.90.2
npm ERR! node_modules/webpack
npm ERR!   peer webpack@"^5.0.0" from css-loader@6.7.2
npm ERR!   node_modules/css-loader
npm ERR!     dev css-loader@"^6.7.1" from the root project
npm ERR!   peer webpack@"^4.0.0 || ^5.0.0" from file-loader@6.2.0
npm ERR!   node_modules/file-loader
npm ERR!     peerOptional file-loader@"*" from url-loader@4.1.1
npm ERR!     node_modules/url-loader
npm ERR!       dev url-loader@"^4.1.1" from the root project
npm ERR!     dev file-loader@"^6.2.0" from the root project
npm ERR!   3 more (html-webpack-plugin, style-loader, url-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.47.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.
npm ERR!
npm ERR!
npm ERR! For a full report see:
npm ERR! D:\nodejs\node_cache\_logs\2024-02-19T09_16_04_397Z-eresolve-report.txt

npm ERR! A complete log of this run can be found in:
npm ERR!     D:\nodejs\node_cache\_logs\2024-02-19T09_16_04_397Z-debug-0.log

这个错误是由于npm在解析依赖关系时发生了冲突导致的。根据错误信息显示,uglifyjs-webpack-plugin@2.2.0 需要 webpack@^4.0.0 作为 peer dependency,但是项目中已经安装了 webpack@5.90.2,这就导致了冲突。

解决这个问题的方法之一是尝试使用`--force`或者`--legacy-peer-deps`选项来强制接受不完全匹配的依赖关系解析。可以尝试运行以下命令来安装 :

npm install --legacy-peer-deps

这将会尝试使用旧的方式来解决依赖关系,可能会解决这个问题。如果还是无法解决,可以尝试更新或者降级uglifyjs-webpack-plugin和相关的依赖版本,以使它们与webpack@5兼容。

npm清除缓存

npm cache clean --force

  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值