You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修复npm安装时的ERESOLVE依赖冲突错误?

解决npm install时的ERESOLVE依赖冲突问题

问题描述

执行npm install时触发ERESOLVE依赖解析错误,核心冲突为:@typescript-eslint/eslint-plugin@7.12.0要求的peer依赖是eslint@^8.56.0,但当前项目已安装eslint@9.5.0,版本不兼容导致依赖无法解析。

完整错误日志

npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: @typescript-eslint/eslint-plugin@7.12.0
npm ERR! Found: eslint@9.5.0
npm ERR! node_modules/eslint
npm ERR!   peer eslint@"^6.0.0 || ^7.0.0 || >=8.0.0" from @eslint-community/eslint-utils@4.4.0
npm ERR!   node_modules/@eslint-community/eslint-utils
npm ERR!     @eslint-community/eslint-utils@"^4.4.0" from @typescript-eslint/utils@7.12.0
npm ERR!     node_modules/@typescript-eslint/eslint-plugin/node_modules/@typescript-eslint/utils
npm ERR!       @typescript-eslint/utils@"7.12.0" from @typescript-eslint/eslint-plugin@7.12.0
npm ERR!       node_modules/@typescript-eslint/eslint-plugin
npm ERR!         @typescript-eslint/eslint-plugin@"^7.10.0" from the root project
npm ERR!       1 more (@typescript-eslint/type-utils)
npm ERR!     @eslint-community/eslint-utils@"^4.2.0" from eslint@9.5.0
npm ERR!   peer eslint@">=7.0.0" from eslint-config-prettier@9.1.0
npm ERR!   node_modules/eslint-config-prettier
npm ERR!     peerOptional eslint-config-prettier@"*" from eslint-plugin-prettier@5.1.3
npm ERR!     node_modules/eslint-plugin-prettier
npm ERR!       eslint-plugin-prettier@"^5.1.3" from the root project
npm ERR!     eslint-config-prettier@"^9.1.0" from the root project
npm ERR!   2 more (eslint-plugin-prettier, the root project)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer eslint@"^8.56.0" from @typescript-eslint/eslint-plugin@7.12.0
npm ERR! node_modules/@typescript-eslint/eslint-plugin
npm ERR!   @typescript-eslint/eslint-plugin@"^7.10.0" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: eslint@8.57.0
npm ERR! node_modules/eslint
npm ERR!   peer eslint@"^8.56.0" from @typescript-eslint/eslint-plugin@7.12.0
npm ERR!   node_modules/@typescript-eslint/eslint-plugin
npm ERR!     @typescript-eslint/eslint-plugin@"^7.10.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 audit fix
  • npm audit fix --force
  • npm install typescript
  • npm install eslint

有效修复方案

方案1:升级@typescript-eslint到兼容ESLint 9的版本

@typescript-eslint v8.x及以上版本已支持ESLint 9,执行以下命令升级相关依赖:

npm install @typescript-eslint/eslint-plugin@latest @typescript-eslint/parser@latest --save-dev

升级完成后重新执行npm install即可解决冲突。

方案2:降级ESLint到@typescript-eslint支持的版本

若暂时不想升级@typescript-eslint,可将ESLint降级至8.x系列的兼容版本:

npm install eslint@8.57.0 --save-dev

随后执行npm install完成依赖安装。

方案3:跳过peer依赖检查(临时应急方案)

如果需要快速完成依赖安装,可使用--legacy-peer-deps参数忽略peer依赖冲突,但该方案可能存在潜在兼容性风险:

npm install --legacy-peer-deps

内容的提问来源于stack exchange,提问作者soeun

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 18:57:20