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
相关推荐
188号安全攻城狮13 分钟前
【前端安全】Trusted Types 全维度技术指南:CSP 原生 DOM XSS 防御终极方案
前端·安全·网络安全·xss
墨渊君36 分钟前
从 0 到 1:用 Node 打通 OpenClaw WebSocket 通信全流程
前端·openai·agent
Novlan11 小时前
一个油猴脚本,解决掘金编辑器「转存失败」的烦恼
前端
前端老石人1 小时前
HTML 入门指南:从规范视角建立正确知识体系
开发语言·前端·html
前端付豪1 小时前
实现右侧记忆面板可编辑
前端·人工智能·后端
DanCheOo1 小时前
从"会用 AI"到"架构 AI":高级前端的认知升级
前端·agent
光影少年1 小时前
React Native项目常见的性能瓶颈有哪些?(JS线程阻塞、UI渲染卡顿、内存泄漏、包体积过大)
javascript·react native·ui
竹林8181 小时前
在Next.js NFT市场中,我如何解决动态路由、链上数据获取与状态同步的连环坑
前端·javascript·next.js
用户69371750013841 小时前
实测!Gemma 4 成功跑在安卓手机上:离线 AI 助手终于来了
android·前端·人工智能