39

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?

Alireza
  • 2,319
  • 2
  • 23
  • 35
Simon
  • 1,966
  • 5
  • 21
  • 35

4 Answers4

49

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.

spierala
  • 2,349
  • 3
  • 25
  • 50
24

In my Angular CLI project I use npm update to update my dependencies. With npm outdated, you can see all outdated dependencies.


Update June 2018

If you're using Angular CLI version 6+, you can use the new ng update <packagename> command to update your dependencies.

⚠️ This will update to the newest major version. If you don't want that stick with npm update. ⚠️

https://angular.io/guide/updating

For simple updates, the CLI command ng update is all you need. Without additional arguments, ng update lists the updates that are available to you and provides recommended steps to update your application to the most current version.

Kim Kern
  • 54,283
  • 17
  • 197
  • 195
  • Ahhh yes. npm outdated is useful too! – Simon Jul 18 '17 at 15:27
  • It's not updating package.json, any ideas? – Simon Jul 18 '17 at 15:30
  • 1
    If you upgrade to npm 5, you don't have to type --save anymore; it becomes the default. Makes life much easier. :) see http://blog.npmjs.org/post/161081169345/v500 – Kim Kern Jul 18 '17 at 18:28
  • Should the ng update command update only minor versions? It upgraded the major version for me (from 7.2.0 to 8.0.0). – Trevor Karjanis Jun 11 '19 at 14:49
  • @TrevorKarjanis Yes, this will also update the major version (and performing most code changes necessary for the update). I've edited the post to reflect that. If you want to stick to the same major version, use `npm update` and make sure to have the corresponding version range in your `package.json`: see https://docs.npmjs.com/misc/semver#caret-ranges-123-025-004 – Kim Kern Jun 12 '19 at 08:57
0

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.

tdy
  • 36,675
  • 19
  • 86
  • 83
0

For me, upgrading from Angular 16.0.0 to 16.1.6 could just be done with:

ng update @angular/cli@16 @angular/core@16

Otto Coster
  • 163
  • 4