npm install命令报错:npm ERR Could not resolve dependency npm ERR peer…

在运行前端代码下载依赖时,使用 npm install 命令安装依赖时遇到错误,报错信息如下:

复制代码
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: project@0.1.0
npm ERR! Found: eslint@7.32.0
npm ERR! node_modules/eslint
npm ERR! eslint@"^7.4.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer eslint@"^5.0.0 || ^6.0.0" from eslint-plugin-vue@6.2.2
npm ERR! dev eslint-plugin-vue@"^6.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! See D: ode ode_cacheeresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR! D: ode ode_cache_logs?2-04-28T06_55_18_256Z-debug-0.log

错误原因

在新版本的npm中,默认情况下,npm install遇到冲突的peerDependencies时将失败。

解决办法

使用--force--legacy-peer-deps选项。

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

建议用 --legacy-peer-deps 选项在终端重新安装即可,该命令相对保险一点。

复制代码
npm install --legacy-peer-deps
相关推荐
Apifox9 分钟前
如何让 Apifox 发布的在线文档具备更好的调试体验?
前端·后端·测试
咔咔一顿操作12 分钟前
【CSS 3D 交互】打造沉浸式 3D 照片墙:结合 JS 实现拖拽交互
前端·javascript·css·3d·交互·css3
0x00014 分钟前
Uniapp - 自定义 Tabbar 实现
前端·uni-app
用户4582031531716 分钟前
Flexbox布局上手:10分钟告别垂直居中难题
前端·css
牛蛙点点申请出战17 分钟前
仿微信语音 WaveView 实现
android·前端·ios
yiyesushu19 分钟前
react + next.js + ethers v6 项目实例
前端
明远湖之鱼20 分钟前
巧用 Puppeteer + Cheerio:批量生成高质量 Emoji 图片
前端·爬虫·node.js
落笔忆梦21 分钟前
利用浏览器空闲时间优化资源加载与渲染
前端·javascript
艾小码22 分钟前
还在用Vue 2硬撑?升级Vue 3的避坑指南来了!
前端·javascript·vue.js
是晓晓吖23 分钟前
page.waitForResponse 执行环境:页面还是 Node.js?
前端·puppeteer