How to upgrade minor version of angular using angular cli

Viewed 13016

This is a simple question but I'm struggling to find the answer via Google...

I have an angular 4 project (created using angular cli) and would like to make use of http interceptors that have just been released in 4.3.

How do I upgrade to this minor release using angular cli?

3 Answers

Major version angular updates should be done with ng update.

npm update for updating angular minor/patch versions has a downside: it will also update other unrelated packages.

You can use npm-check-updates to update just specific packages and you can choose to target patch/minor/major versions.

This command will update all angular package minor (and patch) versions (but it will keep the major versions):

npx npm-check-updates --upgrade --target "minor" --filter "/@angular.*/"

That command gives you a preview of the new versions and updates the package.json accordingly:

enter image description here

Afterwards you can run npm install.

In some cases ng update doesn't update the angular core dependencies with minor version updates.

I've faced a case trying to update from Angular 6.0.0 to 6.1.0, and it didn't work.

I solved this only doing the steps:

  1. Delete the project node_modules directory

  2. Change manually in the package.json all the angular core dependencies libraries:

    common, compiler, compiler-cli, core, forms, http
    platform-browser, platform-browser-dynamic, router 
    

    Like the last 4 lines here:

    "dependencies": {
        "@agm/core": "~1.0.0-beta.3",
        "@angular/animations": "^6.0.9",
        "@angular/cdk": "^6.4.0",
        "@angular/cli": "^6.2.9",
        "@angular/common": "^6.1.x",
        "@angular/core": "^6.1.x",
        "@angular/forms": "^6.1.x",
        "@angular/http": "^6.1.x",
    

    See in the devdependencies for compiler, compiler-cli too.

  3. Run npm install to rebuild node_modules.

  4. After this we have the result of ng --version cli command from 6.0.0 to 6.1.10.

Related