升级typescript-eslint从8.37到8.38时遭遇依赖解析失败问题
升级typescript-eslint从8.37到8.38时的ERESOLVE依赖冲突解决
错误信息
npm error code ERESOLVE npm error ERESOLVE could not resolve npm error npm error While resolving: my-package@0.1.0 npm error Found: @typescript-eslint/eslint-plugin@8.37.0 npm error node_modules/@typescript-eslint/eslint-plugin npm error dev @typescript-eslint/eslint-plugin@"^8.38.0" from the root project npm error @typescript-eslint/eslint-plugin@"8.37.0" from typescript-eslint@8.37.0 npm error node_modules/typescript-eslint npm error dev typescript-eslint@"^8.38.0" from the root project npm error npm error Could not resolve dependency: npm error dev @typescript-eslint/eslint-plugin@"^8.38.0" from the root project npm error npm error Conflicting peer dependency: @typescript-eslint/parser@8.38.0 npm error node_modules/@typescript-eslint/parser npm error peer @typescript-eslint/parser@"^8.38.0" from @typescript-eslint/eslint-plugin@8.38.0 npm error node_modules/@typescript-eslint/eslint-plugin npm error dev @typescript-eslint/eslint-plugin@"^8.38.0" from the root project npm error npm error Fix the upstream dependency conflict, or retry npm error this command with --force or --legacy-peer-deps npm error to accept an incorrect (and potentially broken) dependency resolution.
已尝试无效的操作
- 删除node_modules、package-lock.json并清除npm缓存
- 升级至最新版npm(当前版本:node 24.3.0,npm 11.4.2)
- 更新package.json中所有相关包至8.38版本
问题根源
typescript-eslint元包的8.37版本硬依赖了@typescript-eslint/eslint-plugin@8.37.0,而根项目要求的是^8.38.0,导致版本冲突无法自动解析。
解决方法
方法1:使用npm overrides强制统一版本
在package.json中添加overrides字段,强制指定所有相关包的版本为8.38.0:
"overrides": { "@typescript-eslint/eslint-plugin": "8.38.0", "@typescript-eslint/parser": "8.38.0", "typescript-eslint": "8.38.0" }
添加后执行:
npm install
方法2:直接重新安装指定版本的相关包
执行以下命令,强制安装所有相关包的8.38.0版本:
npm install @typescript-eslint/eslint-plugin@8.38.0 @typescript-eslint/parser@8.38.0 typescript-eslint@8.38.0 --save-dev
方法3:排查间接依赖
如果以上方法无效,执行以下命令查看依赖树,找到引入旧版本typescript-eslint的第三方包:
npm ls typescript-eslint
针对找到的第三方包,要么升级该包到兼容8.38版本的版本,要么在overrides中追加该包的版本强制覆盖。
内容的提问来源于stack exchange,提问作者Richard Collette
相关产品推荐
相关产品推荐

