从 Angular 11 升级到 12 会导致对等依赖冲突

我目前正在从 Angular 11.2.14 升级到 Angular 12.0.5 并且遇到以下问题:

npm ERR! Could not resolve dependency:
npm ERR! dev @angular-devkit/build-angular@"12.0.5" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: @angular/compiler-cli@12.0.5
npm ERR! node_modules/@angular/compiler-cli
npm ERR!   dev @angular/compiler-cli@"12.0.5" from the root project
npm ERR!   peer @angular/compiler-cli@"^12.0.0" from @angular-devkit/build-angular@12.0.5
npm ERR!   node_modules/@angular-devkit/build-angular
npm ERR!     dev @angular-devkit/build-angular@"12.0.5" from the root project
npm ERR!   2 more (@angular/localize, ng-packagr)
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.

我是否正确假设这是因为版本 12.0.512.0.0 之间存在冲突并且它们不兼容?我所有的依赖项现在都具有相同的版本,为什么会出现冲突?

package.json

    "@angular-builders/custom-webpack": "12.1.0",
    "@angular-devkit/build-angular": "12.0.5",
    "@angular/animations": "12.0.5",
    "@angular/cdk": "12.0.5",
    "@angular/cli": "12.0.5",
    "@angular/common": "12.0.5",
    "@angular/compiler": "12.0.5",
    "@angular/compiler-cli": "12.0.5",
    "@angular/core": "12.0.5",
    "@angular/flex-layout": "11.0.0-beta.33",
    "@angular/forms": "12.0.5",
    "@angular/language-service": "12.0.5",
    "@angular/material": "11.2.13",
    "@angular/platform-browser": "12.0.5",
    "@angular/platform-browser-dynamic": "12.0.5",
    "@angular/router": "12.0.5",

非常感谢!

stack overflow Upgrade from Angular 11 to 12 causes peer dependency conflict
原文答案

答案:

作者头像

我必须使用 npm v6 才能成功更新:

npm -g i npm@^6
npm i
ng update @angular/cli@^12 @angular/core@^12
作者头像

当我使用官方更新指南 https://update.angular.io/ 和命令 npx @angular/cli@12 update @angular/core@12 @angular/cli@12 时,我在每个版本的角度更新上都遇到了同样的错误。经过长时间的谷歌搜索和尝试,我找到了下一个角度和角度材料更新的方法(例如 10 到 11 更新):

npx @angular/cli@11 update @angular/core@11 @angular/cli@11

得到主题错误

删除 node_modules 和 package-lock.json

npm install

Git 提交

ng update @angular/core@11 --migrate-only --from 10 --to 11

Git 提交

ng update @angular/cli@11 --migrate-only --from 10 --to 11

Git 提交

npx @angular/cli@11 update @angular/material@11 @angular/flex-layout@11.0.0-beta.33
作者头像

我遇到了同样的问题,这让初学者感到困惑

我最初尝试了这个命令,但我又遇到了另一个错误

ng update @angular/cli @angular/core

然后我找到了这个链接 https://github.com/angular/angular-cli/issues/20843 并且有人说要执行这个全局 cli 命令,这似乎解决了创建新项目时的问题

npm i @angular/cli -g

我现在可以创建我的新项目命令,例如:

ng new example --routing false --style css --skip-git --skip-tests

enter image description here

作者头像

降级npm v6,我在谷歌搜索成功后尝试了很多命令

npm -g i npm@^6
npm i
ng update @angular/cli@^12 @angular/core@^12
作者头像

更新您的 tsconfig.json 然后运行

sudo npm install --force