单个版本更新Angular

Single version update Angular

我必须将 angular 7.x 项目更新到 angular 8.2.0,所以我在线阅读了 ng update

我有一个全局 angular 版本等于我的更新目标版本 (8.2.0),但 ng update 强制我更新到最新版本。

Your global Angular CLI version (8.2.0) is greater than your local
version (7.3.5). The local Angular CLI version is used.

To disable this warning use "ng config -g cli.warnings.versionMismatch false".
    We analyzed your package.json, there are some packages to update:

      Name                                      Version                  Command to update
     ---------------------------------------------------------------------------------------
      @angular/cdk                              7.3.3 -> 13.3.1          ng update @angular/cdk
      @angular/cli                              7.3.5 -> 13.3.0          ng update @angular/cli
      @angular/core                             7.2.8 -> 13.3.0          ng update @angular/core
      @angular/core                             7.2.8 -> 7.2.16          ng update @angular/core
      @angular/fire                             5.1.1 -> 7.3.0           ng update @angular/fire
      @angular/material                         7.3.3 -> 13.3.1          ng update @angular/material
      @nguniversal/aspnetcore-engine            7.1.1 -> 8.2.6           ng update @nguniversal/aspnetcore-engine
      @nguniversal/express-engine               7.1.1 -> 13.1.0          ng update @nguniversal/express-engine
      @ngx-i18nsupport/tooling                  1.1.2 -> 8.0.3           ng update @ngx-i18nsupport/tooling
      ng-mocks                                  7.7.0 -> 13.3.0          ng update ng-mocks


    There might be additional packages that are outdated.
    Run "ng update --all" to try to update all at the same time.

有没有办法使用 ng update --all 来做到这一点?我必须使用 Angular update guide 吗?

我也试过 ng update @angular/cli --from="7.3.5" --to="8.2.0"但是不行。

                  Package "@angular-devkit/build-ng-packagr" has an incompatible peer dependency to "ng-packagr" (requires "^2.2.0 || ^3.0.0 || ^4.0.0", would install "13.3.0").
                  Package "codelyzer" has an incompatible peer dependency to "@angular/core" (requires ">=2.3.1 <8.0.0 || >7.0.0-beta <8.0.0" (extended), would install "13.3.0").
                  Package "ng-mocks" has an incompatible peer dependency to "@angular/forms" (requires ">=5.x <=7.x" (extended), would install "13.3.0").
                  Package "codelyzer" has an incompatible peer dependency to "@angular/compiler" (requires ">=2.3.1 <8.0.0 || >7.0.0-beta <8.0.0" (extended), would install "13.3.0").
                  Package "@angular/http" has an incompatible peer dependency to "@angular/platform-browser" (requires "7.2.8" (extended), would install "13.3.0").
                  Package "@ismaestro/ngx-example-library" has an incompatible peer dependency to "@angular/common" (requires "^6.0.0-rc.0 || ^6.0.0" (extended), would install "13.3.0").
                  Package "@angular/fire" has an incompatible peer dependency to "@angular/platform-browser-dynamic" (requires ">=6.0.0 <8" (extended), would install "13.3.0").
                  Package "@nguniversal/express-engine" has an incompatible peer dependency to "@angular/platform-server" (requires "^7.1.4" (extended), would install "13.3.0").
                  Package "tsickle" has an incompatible peer dependency to "typescript" (requires "~3.3.1", would install "4.6.3").
                  Package "@angular/fire" has an incompatible peer dependency to "zone.js" (requires "^0.8.0", would install "0.11.5").
                  Package "@angular/http" has an incompatible peer dependency to "rxjs" (requires "^6.0.0", would install "7.5.5").```

那是因为当您执行 ng update 时,您并未定义特定版本。 你应该使用类似 ng update @angular/core@10 @angular/cli@10 等的东西...

不建议在一次更新中从 Angular 7 升级到 Angular 13,而应该逐个升级,例如:

  • Angular 7 -> Angular 8,
  • Angular 8 -> Angular 9.1

按照这个 Angular 更新指南,你应该没问题,在底部你有每次更新前你应该做的具体说明 https://update.angular.io/