介绍升级从Ionic 4到Ionic 5时出现的问题(Angular)

首先

当将Ionic4升级到5时,能够顺利并没有问题地完成的人可能会比较少,不是吗?

当然,作为一个人也遇到了神秘的问题,感到困惑的家伙之一。

注意事项

这篇文章只是一个介绍所面临问题的文章,因此并没有详细介绍解决方案!尝试了很多命令后,坦率地说,没有一种强有力的信息可以断言“这个错误的解决方案就是这个!”。

升级之前的环境

Ionic:

   Ionic CLI                     : 6.7.0 (/usr/local/lib/node_modules/@ionic/cli)
   Ionic Framework               : @ionic/angular 5.1.0
   @angular-devkit/build-angular : 0.901.4
   @angular-devkit/schematics    : 8.1.3
   @angular/cli                  : 8.1.3
   @ionic/angular-toolkit        : 2.2.0

Capacitor:

   Capacitor CLI   : 1.2.0
   @capacitor/core : 1.2.0

Cordova:

   Cordova CLI       : 9.0.0 (cordova-lib@9.0.1)
   Cordova Platforms : none
   Cordova Plugins   : no whitelisted plugins (0 plugins total)

Utility:

   cordova-res (update available: 0.14.0) : 0.6.0
   native-run (update available: 1.0.0)   : 0.2.8

System:

   NodeJS : v10.15.1 (/usr/local/bin/node)
   npm    : 6.12.1
   OS     : macOS Mojave
   Xcode  : Xcode 11.2.1 Build version 11B500

参考的網站

首先,我参考的网站有以下三个(尤其是以第二个为主)。

Ionic5已经推出。通过GIF动画介绍最新的Web移动UI框架!

将现有的Ionic 4.x 应用升级到 Ionic 5.x。

将Ionic 4升级到Ionic 5(Angular)。

错误1

将Ionic 4升级到Ionic 5(Angular)
执行此页面中提到的命令时发生

ng update @angular/cli@8 @angular/core@8 --allow-dirty
Repository is not clean.  Update changes will be mixed with pre-existing changes.
Using package manager: 'npm'
Collecting installed dependencies...
Found 50 dependencies.
Fetching dependency metadata from registry...
                  Package "@angular-devkit/build-angular" has an incompatible peer dependency to "@angular/compiler-cli" (requires ">=9.0.0 < 10" (extended), would install "8.2.14").
                  Package "@angular-devkit/build-angular" has an incompatible peer dependency to "typescript" (requires ">=3.6 < 3.9", would install "3.5.3").
Incompatible peer dependencies found.
Peer dependency warnings when installing dependencies means that those dependencies might not work correctly together.
You can use the '--force' option to ignore incompatible peer dependencies and instead address these warnings later.

好的,不明白!

错误2

ng update @angular/core @angular/cli --allow-dirty
Your global Angular CLI version (9.1.4) is greater than your local
version (8.1.3). The local Angular CLI version is used.

To disable this warning use "ng config -g cli.warnings.versionMismatch false".
Repository is not clean.  Update changes will be mixed with pre-existing changes.
Using package manager: 'npm'
Collecting installed dependencies...
Found 51 dependencies.
Fetching dependency metadata from registry...
                  Package "@angular/platform-browser" has a missing peer dependency of "@angular/animations" @ "9.1.4".
Incompatible peer dependencies found.
Peer dependency warnings when installing dependencies means that those dependencies might not work correctly together.
You can use the '--force' option to ignore incompatible peer dependencies and instead address these warnings later.

我知道全局的Angular CLI和本地的Angular CLI是不一样的,但是要怎么办呢?哈哈

错误3

ng update @angular/cli
Your global Angular CLI version (9.1.4) is greater than your local
version (8.1.3). The local Angular CLI version is used.

To disable this warning use "ng config -g cli.warnings.versionMismatch false".
Repository is not clean.  Please commit or stash any changes before updating.

顺利运行的第一个命令

npm install --save-dev @angular/cli@latest

参考这个以后,明明一直都有出现这个下面的错误,不知道为什么用这个方法却奇迹般地成功了。。。

Your global Angular CLI version (9.1.4) is greater than your local
version (8.1.3). The local Angular CLI version is used.

To disable this warning use "ng config -g cli.warnings.versionMismatch false".
Repository is not clean.  Please commit or stash any changes before updating.

执行此命令后,@angular/cli的数值发生改变了!

Ionic:

   Ionic CLI                     : 6.7.0 (/usr/local/lib/node_modules/@ionic/cli)
   Ionic Framework               : @ionic/angular 5.1.0
   @angular-devkit/build-angular : 0.901.4
   @angular-devkit/schematics    : 8.1.3
   @angular/cli                  : 9.1.4
   @ionic/angular-toolkit        : 2.2.0

这是一个运行顺利的命令,第二个。

ng update @angular/cli @angular/core --allow-dirty
Repository is not clean. Please commit or stash any changes before updating.

在执行上述的ng update命令时,发生了这个错误。

通过参考这个并加上–allow-dirty选项,成功执行了。

最终/最后

不要放弃,尝试各种命令吧!我尝试了太多,完全记不得试了哪些命令了…

广告
将在 10 秒后关闭
bannerAds