npm install及Heroku部署时ERESOLVE依赖冲突问题求助
解决Angular依赖冲突(ERESOLVE)问题
错误信息
Installing node modules npm ERR! code ERESOLVE npm ERR! ERESOLVE could not resolve npm ERR! npm ERR! While resolving: @angular-devkit/build-angular@15.0.0 npm ERR! Found: typescript@4.9.3 npm ERR! node_modules/typescript npm ERR! dev typescript@"~4.9.3" from the root project npm ERR! npm ERR! Could not resolve dependency: npm ERR! peer typescript@"~4.8.2" from @angular-devkit/build-angular@15.0.0 npm ERR! node_modules/@angular-devkit/build-angular npm ERR! dev @angular-devkit/build-angular@"^15.0.0" from the root project npm ERR! npm ERR! Conflicting peer dependency: typescript@4.8.4 npm ERR! node_modules/typescript npm ERR! peer typescript@"~4.8.2" from @angular-devkit/build-angular@15.0.0 npm ERR! node_modules/@angular-devkit/build-angular npm ERR! dev @angular-devkit/build-angular@"^15.0.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 /tmp/npmcache.zQoom/eresolve-report.txt for a full report. npm ERR! A complete log of this run can be found in: npm ERR! /tmp/npmcache.zQoom/_logs/2022-11-19T21_40_57_670Z-debug-0.log -----> Build failed
解决方案
方案1:降级TypeScript到兼容版本
- 打开项目根目录的
package.json,找到typescript依赖项,将版本从~4.9.3修改为~4.8.4 - 执行命令:
npm install
方案2:升级Angular构建工具以支持当前TypeScript版本
- Angular 15.1及以上版本的
@angular-devkit/build-angular已支持TypeScript 4.9,执行命令升级:npm install @angular-devkit/build-angular@^15.1.0 --save-dev - 之后执行:
npm install
方案3:清理缓存后重新安装
- 删除本地依赖文件和锁文件:
- macOS/Linux:
rm -rf node_modules package-lock.json - Windows:
rmdir /s /q node_modules && del package-lock.json
- macOS/Linux:
- 清理npm缓存:
npm cache clean --force - 重新安装依赖:
npm install
内容的提问来源于stack exchange,提问作者user15674541
相关产品推荐
相关产品推荐

