Angular依赖树解析失败求助:创建首个项目遇ERESOLVE错误
Angular项目创建时ERESOLVE依赖冲突解决
完成Node.js和Angular安装后,创建第一个项目时遇到如下依赖树解析错误:
54 error code ERESOLVE 55 error ERESOLVE unable to resolve dependency tree 56 error 57 error While resolving: hello-world2@0.0.0 57 error Found: @angular/core@15.1.3 57 error node_modules/@angular/core 57 error @angular/core@"^15.1.0" from the root project 57 error 57 error Could not resolve dependency: 57 error peer @angular/core@"15.1.4" from @angular/animations@15.1.4 57 error node_modules/@angular/animations 57 error @angular/animations@"^15.1.0" from the root project 57 error 57 error Fix the upstream dependency conflict, or retry 57 error this command with --force or --legacy-peer-deps 57 error to accept an incorrect (and potentially broken) dependency resolution. 58 error 58 error 58 error For a full report see: 58 error C:\Users\vule2\AppData\Local\npm-cache\_logs\2023-02-08T18_19_54_573Z-eresolve-report.txt
解决方法
方案1:创建项目时添加--legacy-peer-deps参数(新手首选)
直接用以下命令创建项目,跳过严格的peer依赖版本检查:ng new hello-world2 --legacy-peer-deps方案2:更新Angular CLI到匹配版本
- 查看当前CLI版本:
ng version - 如果CLI版本不是15.1.4,全局更新:
npm install -g @angular/cli@15.1.4 - 重新创建项目,此时生成的依赖版本会自动匹配。
- 查看当前CLI版本:
方案3:手动调整已创建项目的依赖版本
如果已经创建了项目,打开项目根目录的package.json文件,将@angular/core的版本修改为"^15.1.4",保存后运行:npm install
内容的提问来源于stack exchange,提问作者Vukašin
相关产品推荐
相关产品推荐

