ng update to specific Angular version

前端 未结 5 1062
感情败类
感情败类 2020-12-18 18:13

I would like to update Angular from version 5.0 to version 6.1. The instructions at https://update.angular.io/ suggest using ng update @angular/core to update.

相关标签:
5条回答
  • 2020-12-18 18:33

    You can use the @ symbol to specify the version on each package desired. The currently recommend approach to upgrading Angular to a newer version (or version you dictate) is to use the following command:

    ng update @angular/cli @angular/core
    

    In this case let's say I wanted to upgrade to 8.1.1 instead of the latest version of 8.2.0 I would use the following:

    ng update @angular/cli@8.1.1 @angular/core@8.1.1
    

    This is the same way you specify a specific version when doing any npm installs as explained here.

    0 讨论(0)
  • 2020-12-18 18:35

    According to the documentation you will need to define a From..

    --to=to     
    
    Version up to which to apply migrations. Only available with a single package being updated, and only on migrations only. Requires from to be specified. Default to the installed version detected.
    
    0 讨论(0)
  • 2020-12-18 18:44

    Adding this here, since this comes up in search results and the answers provided here didn't work for me.

    What worked for me was using ng update @angular/core@7.0.0. This should probably be noted in the Angular Update Guide (https://update.angular.io/), but it's not. Since that page throws a notice up when upgrading across more than one major version at a time, but using the recommended command ng update @angular/core upgrades to the latest release (which could be across more than one major version), perhaps this should be changed.

    0 讨论(0)
  • 2020-12-18 18:50

    To Remove Circular Dependencies For all updation and avoiding the circular dependencies (no need to use ng update @angular/cli@8.1.1 @angular/core@8.1.1 etc etc), in general, use the below command
    ng update --force --all

    0 讨论(0)
  • 2020-12-18 18:57

    If you are upgrading to an older version, as recommended by Angular to upgrade to the next major version first instead of moving directly to the latest version (like current latest version is v10 and you are upgrading from v8, its recommended to first upgrade to v9 and then to v10), then you have to provide the update the dependencies/package to the latest version compatible with Angular9.

    For upgrading, first check the required dependencies to be updated with the help of

    ng update - which will list all the dependencies you have to update(see image)

    Referring to the picture, there are 6 packages to update which we will update to the version we are upgrading to(in this case it is v9) using ng update command:

    ng update @angular/cdk@9 @angular/cli@9 @angular/core@9 @angular/material@9 @ngx-pwa/local-storage@9 rxjs --force
    

    (you can define specific versions of the packages by going to npm packages, for example - @angular/core@9.1.2 as 9.1.2 is the latest stable release of @angular/core package for angular9).

    This will update your project to angular v9.

    Similarly, for v10, you need to follow the above process.

    [Note: For the latest angular version(which is v10 at the time of writing this), you need not provide the version during update and you can directly update as:

    ng update @angular/cdk @angular/cli --force

    You can also use npm outdated to view the outdated packages which needs to be updated.

    Hope this answer proves helpful for you. If you find any issues, please comment and I'll try to provide solution.

    0 讨论(0)
提交回复
热议问题