40

How to update to Angular 5? This is from my package.json:

"dependencies": {
    "@angular/animations": "5.0.0",
    "@angular/common": "5.0.0",
    "@angular/compiler": "5.0.0",
    "@angular/core": "5.0.0",
    "@angular/forms": "5.0.0",
    "@angular/http": "5.0.0",
    "@angular/platform-browser": "5.0.0",
    "@angular/platform-browser-dynamic": "5.0.0",
    "@angular/router": "5.0.0",
    "@types/jwt-decode": "^2.2.1",
    "bootstrap": "^3.3.7",
    "bootstrap-sass": "^3.3.7",
    "classlist.js": "^1.1.20150312",
    "core-js": "^2.4.1",
    "intl": "^1.2.5",
    "jquery": "^3.2.1",
    "jwt-decode": "^2.2.0",
    "rxjs": "^5.4.2",
    "zone.js": "^0.8.14"
},
"devDependencies": {
    "@angular/cli": "1.4.0-rc.2",
    "@angular/compiler-cli": "5.0.0",
    "@angular/language-service": "5.0.0",
    "@types/jasmine": "~2.5.53",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~6.0.60",
    "angular-ide": "^0.9.31",
    "codelyzer": "~3.1.1",
    "jasmine-core": "~2.6.2",
    "jasmine-spec-reporter": "~4.1.0",
    "karma": "~1.7.0",
    "karma-chrome-launcher": "~2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "node-sass": "^4.5.3",
    "protractor": "~5.1.2",
    "raw-loader": "^0.5.1",
    "sass-loader": "^6.0.6",
    "sw-precache": "^5.2.0",
    "ts-node": "~3.2.0",
    "tslint": "~5.3.2",
    "typescript": "~2.3.3"
}

When I run npm install I get this error

npm ERR! Windows_NT 6.1.7601 npm ERR! argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "install" npm ERR! node v6.11.2 npm ERR! npm v3.10.10 npm ERR! code ETARGET

npm ERR! notarget No compatible version found: @angular/common@5.0.0 npm ERR! notarget Valid install targets: npm ERR! notarget 5.0.0-rc.0, 5.0.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, 0.0.0-1, 0.0.0-0 npm ERR! notarget npm ERR! notarget This is most likely not a problem with npm itself. npm ERR! notarget In most cases you or one of your dependencies are requesting npm ERR! notarget a package version that doesn't exist. npm ERR! notarget npm ERR! notarget It was specified as a dependency of 'gizza' npm ERR! notarget

I know Angular 5 is still in beta but I want to test it.

EDIT: Version 5.0.0 now does exist as of Nov. 1st 2017

Melchia
  • 22,578
  • 22
  • 103
  • 117

9 Answers9

55

As Now, angular 5 has been released officially on 1st Novemebr 2017, So for those who want to update your old angular applications to angular 5:

1) The Angular team has also put a handy tool to make upgrading from any version to angular 5, as simple as possible.

2) You will have to upgrade all of your angular packages to version 5.0, run the following command:

npm install @angular/animations@^5.0.0 @angular/common@^5.0.0 @angular/compiler@^5.0.0 @angular/compiler-cli@^5.0.0 @angular/core@^5.0.0 @angular/forms@^5.0.0 @angular/http@^5.0.0 @angular/platform-browser@^5.0.0 @angular/platform-browser-dynamic@^5.0.0 @angular/platform-server@^5.0.0 @angular/router@^5.0.0 zone.js@^0.8.4 @angular/upgrade@^5.0.0 typescript@2.4.2 rxjs@^5.5.2

3) Angular 5 now also depends on TypeScript 2.4.2 and RxJS 5.5.2, so you’ll have to upgrade those package as well.

npm install typescript@2.4.2 --save-exact 

4) If you rely on the date, currency, decimal, or percent pipes, in 5 you will see minor changes to the format. For applications using locales other than en-us you will need to import it and optionally locale_extended_fr from @angular/common/i18n_data/locale_fr and registerLocaleData(local). For more information on pipes breaking changes: https://stackoverflow.com/a/47263949/2810015

5) Use of implements instead of extends with any lifecycle events : Ensure you don't use extends OnInit, or use extends with any lifecycle event. Instead use implements .

6) Switch from HttpModule and the Http service to HttpClientModule and the HttpClient service. HttpClient simplifies the default ergonomics (You don't need to map to json anymore and remove any map(res => res.json()) calls, which are no longer needed.) and now supports typed return values and interceptors.

7) The recommended way of importing operators in RxJS 5.5 is from rxjs/operators.

import { map, filter, mergeMap, tap } from 'rxjs/operators';

I have tried to explain more here. https://onlyforcoder.blogspot.in/2017/11/angular-5-upgrade-your-project-To-Angular5.html

timemachine3030
  • 362
  • 1
  • 9
Nimish goel
  • 2,561
  • 6
  • 27
  • 42
  • Thanks it's really helpful +1 – Melchia Nov 08 '17 at 15:06
  • 1
    Fail for me. I get npm ERR! notarget No matching version found for @angular/compiler@'5.0.0' – AntonK Nov 20 '17 at 23:17
  • https://www.npmjs.com/package/@angular/compiler, You can check, @angular/compilerversion 5.0.2 has been released. Try this version to install, IF this also fails for you. try this `npm install https://github.com/angular/angular/tree/master/packages/compiler` – Nimish goel Nov 21 '17 at 05:42
  • I can verify that i'm getting the exact error when I run the command from the upgrade tool that Google provided. I don't understand why this happens. When I go to npm view @angular/core versions --json I can see the version exists – Diskdrive Nov 30 '17 at 03:42
  • 2
    for those getting "No matching version found for" error, you need to remove the ' ' on the version part – Lexy Feito Nov 30 '17 at 16:27
  • 1
    I have been fighting ( _This version of CLI is only compatible with Angular version 5.0.0 or higher._ ) for days until I did your rather long command above and I am finally able to `ng serve` again. Cannot tell you how much grief you have ended for me. – Aggie Jon of 87 Jun 08 '18 at 08:29
15

EDIT: Version 5.0.0 now does exist as of Nov. 1st 2017

NPM is telling you 5.0.0 doesnt exist. change your package.json to one of the suggested release candidates like 5.0.0-rc.0. There is a good chance they aren't all exactly that either so read the npm error it is actually helpful in this case.

"dependencies": {
    "@angular/animations": "5.0.0-rc.0",
    "@angular/common": "5.0.0-rc.0",
    "@angular/compiler": "5.0.0-rc.0",
    "@angular/core": "5.0.0-rc.0",
    "@angular/forms": "5.0.0-rc.0",
    "@angular/http": "5.0.0-rc.0",
    "@angular/platform-browser": "5.0.0-rc.0",
    "@angular/platform-browser-dynamic": "5.0.0-rc.0",
    "@angular/router": "5.0.0-rc.0",
    "@types/jwt-decode": "^2.2.1",
    "bootstrap": "^3.3.7",
    "bootstrap-sass": "^3.3.7",
    "classlist.js": "^1.1.20150312",
    "core-js": "^2.4.1",
    "intl": "^1.2.5",
    "jquery": "^3.2.1",
    "jwt-decode": "^2.2.0",
    "rxjs": "^5.4.2",
    "zone.js": "^0.8.14"
},
"devDependencies": {
    "@angular/cli": "1.4.0-rc.2",
    "@angular/compiler-cli": "5.0.0",
    "@angular/language-service": "5.0.0",
    "@types/jasmine": "~2.5.53",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~6.0.60",
    "angular-ide": "^0.9.31",
    "codelyzer": "~3.1.1",
    "jasmine-core": "~2.6.2",
    "jasmine-spec-reporter": "~4.1.0",
    "karma": "~1.7.0",
    "karma-chrome-launcher": "~2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "node-sass": "^4.5.3",
    "protractor": "~5.1.2",
    "raw-loader": "^0.5.1",
    "sass-loader": "^6.0.6",
    "sw-precache": "^5.2.0",
    "ts-node": "~3.2.0",
    "tslint": "~5.3.2",
    "typescript": "~2.3.3"
}
rjustin
  • 1,399
  • 8
  • 19
13

Edit: This is the latest Angular 5 working dependencies:

  "dependencies": {
    "@angular/animations": "^5.2.0",
    "@angular/common": "^5.2.0",
    "@angular/compiler": "^5.2.0",
    "@angular/core": "^5.2.0",
    "@angular/forms": "^5.2.0",
    "@angular/http": "^5.2.0",
    "@angular/platform-browser": "^5.2.0",
    "@angular/platform-browser-dynamic": "^5.2.0",
    "@angular/router": "^5.2.0",
    "core-js": "^2.4.1",
    "rxjs": "^5.5.6",
    "zone.js": "^0.8.19"
  },
  "devDependencies": {
    "@angular/cli": "1.6.7",
    "@angular/compiler-cli": "^5.2.0",
    "@angular/language-service": "^5.2.0",
    "@types/jasmine": "~2.8.3",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~6.0.60",
    "codelyzer": "^4.0.1",
    "jasmine-core": "~2.8.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~2.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~4.1.0",
    "tslint": "~5.9.1",
    "typescript": "~2.5.3"
  }

Just copy Paste & run npm install

Community
  • 1
  • 1
Melchia
  • 22,578
  • 22
  • 103
  • 117
3

I got the same error even when pasting the command from the Angular upgrade guide.

In the end, I just changed the versions to the latest and it worked.

npm install @angular/animations@latest @angular/common@latest @angular/compiler@latest @angular/compiler-cli@latest @angular/core@latest @angular/forms@latest @angular/http@latest @angular/platform-browser@latest @angular/platform-browser-dynamic@latest @angular/platform-server@latest @angular/router@latest rxjs@latest --save

npm install typescript@2.4.2 --save-exact

I'm unsure why this error is occurring because even when I type in

 npm view @angular/core versions --json

I can see that the version actually exists. My only theory is maybe it's cause I'm on Windows and the Windows version of NPM doesn't like those version numbers...

Diskdrive
  • 18,107
  • 27
  • 101
  • 167
3

Original Answer by @Vishal Gulati: https://stackoverflow.com/a/47132265/6877180

Quick Overview:

Upgrade Angular with all its packages to the latest version.

npm install typescript@2.4 --save-dev
npm install @angular/common@latest @angular/compiler@latest @angular/compiler-cli@latest @angular/core@latest @angular/forms@latest @angular/http@latest @angular/platform-browser@latest @angular/platform-browser-dynamic@latest @angular/platform-server@latest @angular/router@latest @angular/animations@latest --save

Upgrade CLI if needed

npm uninstall -g @angular/cli
npm cache clean
npm install -g @angular/cli@latest
clemens
  • 16,716
  • 11
  • 50
  • 65
Akshay Thorve
  • 678
  • 6
  • 10
2

Here is the command to update Angular CLI in version 5.2.0

npm install @angular/compiler-cli@5.2.0

Sheo Dayal Singh
  • 1,591
  • 19
  • 11
1

This problem is occur because of npm version In order to work in Angular 5 ;

"node": ">=6.9.5 <7.0.0",
"npm": ">=3.10.7 <4.0.0",
"yarn": ">=1.0.2 <2.0.0"
Dr. X
  • 2,890
  • 2
  • 15
  • 37
  • my npm version is 3.10.10 – Melchia Sep 29 '17 at 22:46
  • 1
    In addition, u can read the error to change the version of package.json like @angular/common@5.0.0 npm ERR! notarget Valid install targets: npm ERR! notarget 5.0.0-rc.0, 5.0.0-beta.7. This means that you have to change the version @angular/common@5.0.0 to @angular/common@5.0.0-rc.0 or @angular/common@5.0.0-beta.7 anf goes like in error. – Dr. X Sep 29 '17 at 22:48
1

Basically, there’re few important steps to achieve that.

  1. Upgrade Angular CLI to the latest version.
  2. Modify Angular 4 app dependencies and Update the dependencies.

That’s it, this way you can easily upgrade your Angular 4 app to Angular 5, Read more

Mohit Tanwani
  • 6,608
  • 2
  • 14
  • 32
1

Before updating, rename your template tags to ng-template.

Update all of your dependencies to the latest Angular and the right version of TypeScript. If you are using Windows, you can use:

npm install @angular/animations@'^5.0.0' @angular/common@'^5.0.0' @angular/compiler@'^5.0.0' @angular/compiler-cli@'^5.0.0' @angular/core@'^5.0.0' @angular/forms@'^5.0.0' @angular/http@'^5.0.0' @angular/platform-browser@'^5.0.0' @angular/platform-browser-dynamic@'^5.0.0' @angular/platform-server@'^5.0.0' @angular/router@'^5.0.0' typescript@2.4.2 rxjs@'^5.5.2'

npm install typescript@2.4.2 --save-exact

Lijo
  • 6,498
  • 5
  • 49
  • 60