Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update angular 2 in Angular CLI

Tags:

angular

How do I update Angular 2 version? I use Angular CLI 1.0.0-beta.20-4 and I tried npm update --save but it does not do anything.

Below is my package.json file at the moment. Appreciate any help on this.

{
  "name": "todo1",
  "version": "0.0.0",
  "license": "MIT",
  "angular-cli": {},
  "scripts": {
    "start": "ng serve",
    "lint": "tslint \"src/**/*.ts\"",
    "test": "ng test",
    "pree2e": "webdriver-manager update",
    "e2e": "protractor"
  },
  "private": true,
  "dependencies": {
    "@angular/common": "2.2.1",
    "@angular/compiler": "2.2.1",
    "@angular/core": "2.2.1",
    "@angular/forms": "2.2.1",
    "@angular/http": "2.2.1",
    "@angular/material": "^2.0.0-alpha.11-3",
    "@angular/platform-browser": "2.2.1",
    "@angular/platform-browser-dynamic": "2.2.1",
    "@angular/router": "3.0.0",
    "@types/hammerjs": "^2.0.33",
    "@types/lodash": "^4.14.43",
    "angular2-jwt": "^0.1.25",
    "angular2-uuid": "^1.1.0",
    "core-js": "^2.4.1",
    "hammerjs": "^2.0.8",
    "lodash": "^4.17.2",
    "material-design-icons": "^3.0.1",
    "rxjs": "5.0.0-beta.12",
    "ts-helpers": "^1.1.1",
    "zone.js": "^0.6.23"
  },
  "devDependencies": {
    "@types/hammerjs": "^2.0.33",
    "@types/jasmine": "^2.2.30",
    "angular-cli": "^1.0.0-beta.20-4",
    "codelyzer": "~0.0.26",
    "jasmine-core": "2.4.1",
    "jasmine-spec-reporter": "2.5.0",
    "karma": "1.2.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.0.2",
    "karma-remap-istanbul": "^0.2.1",
    "protractor": "4.0.5",
    "ts-node": "1.2.1",
    "tslint": "3.13.0",
    "typescript": "2.0.2"
  }
}
like image 724
Ka Tech Avatar asked Dec 19 '16 11:12

Ka Tech


People also ask

How do I update Angular CLI?

Update Angular CLI version GloballyFirst uninstall the existing Angular cli packages. Then run npm cache verify command to clear the node packages cache. Then install latest Angular CLI version using npm install -g @angular/cli@latest command.

How do I change NG version?

ng updatelink To update to the next beta or pre-release version, use the --next=true option. To update from one major version to another, use the format ng update @angular/cli@^<major_version> @angular/core@^<major_version> .


2 Answers

You can change the @angular versions to use a caret range so NPM will install the latest package up to the next major release.

  "dependencies": {
    "@angular/common": "^2.2.1",
    "@angular/compiler": "^2.2.1",
    "@angular/core": "^2.2.1",
    "@angular/forms": "^2.2.1",
    "@angular/http": "^2.2.1",

Also it would be worth updating to the latest angular-cli version. See here for instructions.

like image 151
JayChase Avatar answered Nov 13 '22 22:11

JayChase


The main issue you have here is that npm update will only update to the latest compatible version of each module with a limit of the highest version specified in the package.json.

The safest way to do this is to update your package.json to have a wildcard for the minor and patch sections. Angular 2 (as opposed to angular 1) uses semVer (http://semver.org/) so you can safely wildcard the minor and patch parts.

"@angular/common": "2.*.*",
"@angular/compiler": "2.*.*",
"@angular/core": "2.*.*",
"@angular/forms": "2.*.*",
"@angular/http": "2.*.*",
"@angular/material": "^2.0.0-alpha.11-3",
"@angular/platform-browser": "2.*.*",
"@angular/platform-browser-dynamic": "2.*.*",
"@angular/router": "3.0.0",

Run npm update / npm install again and you should upgrade.

like image 35
Peter Grainger Avatar answered Nov 13 '22 21:11

Peter Grainger