47

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?

5 Answers 5

79

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.

Sign up to request clarification or add additional context in comments.

1 Comment

This one is pretty handy for minor updates thx !
27

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.

5 Comments

Ahhh yes. npm outdated is useful too!
It's not updating package.json, any ideas?
If you upgrade to npm 5, you don't have to type --save anymore; it becomes the default. Makes life much easier. :) see blog.npmjs.org/post/161081169345/v500
Should the ng update command update only minor versions? It upgraded the major version for me (from 7.2.0 to 8.0.0).
@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 docs.npmjs.com/misc/semver#caret-ranges-123-025-004
9

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

2 Comments

the official angular cli documentation specifies it like this (it worked for me): ng update @angular/cli@^16 @angular/core@^16
Here is the link: angular.dev/cli/update
0

ALTERNATIVE using dependabot.

I recently faced the same issue (or, i was fed up to face it for each angular update) so I made a bit of googling and found about dependabot groups.

I was already using dependabot to manage my dependencies, but it was still annoying to update Angular one PR at a time, with the npm checks not happy about the npm install failing until all angular dependencies were up-to-date (which resulted in creating a separate branch, executing the npm command of the actual top voted answer of this post (very useful !) and merging that branch instead).

I also had the issue when updating Microsoft.whatever following .NET versioning. I ended up with 10+ commits each updating only a single line in the app. Which is IMO "destroying" the git history as to find a certain commit (eg. debugging purposes) it would be kind of difficult to find the right one in the middle of lots of 1-line commits (and dependabot would look like a better contributor than me on my own project :D)

I updated my file as the following to group the dependencies updates :

version: 2
updates:
  - package-ecosystem: "npm"
    directory: "ClientApp/"
    schedule:
      interval: "monthly"
    open-pull-requests-limit: 10
    groups:
      angular:
        patterns:
          - "@angular*"
      fontawesome:
        patterns:
          - "@fortawesome*"

See the documentation for other dependabot configs

NB : I still have to improve the file as it does not make any differences between patch, minor and major updates. But it solves this issue at the moment

Comments

-1

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.