首页 前端知识 vue npm install 依赖冲突

vue npm install 依赖冲突

2024-06-16 09:06:08 前端知识 前端哥 197 437 我要收藏

报错原因:在执行 npm install 存在依赖冲突。

npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: compression-webpack-plugin@3.1.0
npm ERR! Found: webpack@3.12.0
npm ERR! node_modules/webpack
npm ERR!   peer webpack@"2 || 3 || 4" from babel-loader@7.1.5
npm ERR!   node_modules/babel-loader
npm ERR!     babel-loader@"^7.1.2" from vue-photo-preview@1.1.3
npm ERR!     node_modules/vue-photo-preview
npm ERR!       vue-photo-preview@"^1.1.3" from the root project
npm ERR!   peer webpack@"^3.1.0" from extract-text-webpack-plugin@3.0.2
npm ERR!   node_modules/extract-text-webpack-plugin
npm ERR!     extract-text-webpack-plugin@"^3.0.1" from vue-photo-preview@1.1.3
npm ERR!     node_modules/vue-photo-preview
npm ERR!       vue-photo-preview@"^1.1.3" from the root project
npm ERR!   9 more (file-loader, less-loader, uglifyjs-webpack-plugin, ...)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer webpack@"^4.3.0 || ^5.0.0" from compression-webpack-plugin@3.1.0
npm ERR! node_modules/compression-webpack-plugin
npm ERR!   dev compression-webpack-plugin@"^3.1.0" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: webpack@5.89.0
npm ERR! node_modules/webpack
npm ERR!   peer webpack@"^4.3.0 || ^5.0.0" from compression-webpack-plugin@3.1.0
npm ERR!   node_modules/compression-webpack-plugin
npm ERR!     dev compression-webpack-plugin@"^3.1.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.

 解决方案:

使用--force--legacy-peer-deps可解决这种情况。

--force 会无视冲突,并强制获取远端npm库资源,当有资源冲突时覆盖掉原先的版本。
--legacy-peer-deps:安装时忽略所有peerDependencies,忽视依赖冲突,采用npm版本4到版本6的样式去安装依赖,已有的依赖不会覆盖。

建议用--legacy-peer-deps 比较保险一点

在终端重新安装即可解决

npm install --legacy-peer-deps

转载请注明出处或者链接地址:https://www.qianduange.cn//article/12409.html
标签
评论
发布的文章

前端开发 4: jQuery

2024-06-22 01:06:02

网页开发 HTML

2024-06-22 01:06:17

大家推荐的文章
会员中心 联系我 留言建议 回顶部
复制成功!