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
相关推荐
江公望4 分钟前
VUE3中,reactive()和ref()的区别10分钟讲清楚
前端·javascript·vue.js
攀登的牵牛花7 分钟前
前端向架构突围系列 - 框架设计(二):糟糕的代码有哪些特点?
前端·架构
EndingCoder18 分钟前
函数基础:参数和返回类型
linux·前端·ubuntu·typescript
码客前端24 分钟前
理解 Flex 布局中的 flex:1 与 min-width: 0 问题
前端·css·css3
Komorebi゛24 分钟前
【CSS】圆锥渐变流光效果边框样式实现
前端·css
工藤学编程37 分钟前
零基础学AI大模型之CoT思维链和ReAct推理行动
前端·人工智能·react.js
徐同保37 分钟前
上传文件,在前端用 pdf.js 提取 上传的pdf文件中的图片
前端·javascript·pdf
怕浪猫38 分钟前
React从入门到出门第四章 组件通讯与全局状态管理
前端·javascript·react.js
博主花神39 分钟前
【React】扩展知识点
javascript·react.js·ecmascript
欧阳天风1 小时前
用setTimeout代替setInterval
开发语言·前端·javascript