Using ng --version
I got:
@angular/cli: 1.0.0
which is not the latest release available.
Since I have Angular CLI globally installed on my system, in order to upgrade it I tried:
npm update angular-cli -g
But it does not work, because it stays to 1.0.0 version.
This question is related to
angular
angular-cli
This command works fine:
npm upgrade -g @angular/cli
If you have any difficulties managing your global CLI version it is better to use NVM: MAC, Windows.
To update the local CLI in your Angular project follow this steps:
Starting from CLI v6 you can just run ng update
in order to get your dependencies updated automatically to a new version.
ng update @angular/cli
With ng update
sometimes you might want to add --force
flag.
You can also pass --all
flag to upgrade all packages at the same time.
ng update --all --force
If you want just to migrate CLI just run this:
ng update @angular/cli --migrateOnly
You can also pass flag --from=from
- version from which to migrate from, e.g --from=1.7.4
. This flag is only available with a single package being updated, and only on migration only.
After update is done make sure that the version of typescript you got installed supported by your current angular version, otherwise you might need to downgrade the typescript version. Also bear in mind that usually the latest version of angular won't support the latest version of the typescript.
Checkout
Angular CLI / Angular / NodeJS / Typescript
compatibility versions here
Also checkout this guide Updating your Angular projects and update.angular.io
OLD ANSWER:
All you need to do is to diff with angular-cli-diff and apply the changes in your current project.
Here is the steps:
File changed
tabnpm install
/ yarn
npm scripts
(more details here: https://stackoverflow.com/a/45431592/415078)In my case, I have installed angular-cli locally using npm install --save-dev angular-cli. So, when I use command npm install -g @angular/cli, it generates error saying that "Your global Angular CLI version (1.7.3) is greater than your local version (1.4.9)". Please note that angular-cli, @angular/cli and @angular/cli@latest are two different cli's. What solves this is uninstall all cli and then install latest angular cli using npm install -g @angular/cli@latest
In addition to @ShinDarth answer.
I did what he said but my package did not updated the angular version, and I know that this post is about angular-cli
, but i think that this can help too.
-ng new projectname
that generated a package.-npm install
.Now my ng serve
is working again, maybe there is a better way to do all that, if someone know, please share, because this is a pain to do with all projects that need update.
ng6+ -> 7.0
Update RxJS (depends on RxJS 6.3)
npm install -g rxjs-tslint
rxjs-5-to-6-migrate -p src/tsconfig.app.json
Remove rxjs-compat
Then update the core packages and Cli:
ng update @angular/cli @angular/core
(Optional: update Node.js to version 10 which is supported in NG7)
ng6+ (Cli 6.0+): features simplified commands
First, update your Cli
npm install -g @angular/cli
npm install @angular/cli
ng update @angular/cli
Then, update your core packages
ng update @angular/core
If you use RxJS, run
ng update rxjs
It will update RxJS to version 6 and install the rxjs-compat
package under the hood.
If you run into build errors, try a manual install of:
npm i rxjs-compat
npm i @angular-devkit/build-angular
Lastly, check your version
ng v
Note on production build:
ng6 no longer uses intl
in polyfills.ts
//remove them to avoid errors
import 'intl';
import 'intl/locale-data/jsonp/en';
ng5+ (Cli 1.5+)
npm install @angular/{animations,common,compiler,compiler-cli,core,forms,http,platform-browser,platform-browser-dynamic,platform-server,router}@next [email protected] rxjs@'^5.5.2'
npm install [email protected] --save-exact
Note:
After updating both the global and local package, clear the cache to avoid errors:
npm cache verify (recommended)
npm cache clean (for older npm versions)
Here are the official references:
The following approach worked for me:
npm uninstall -g @angular/cli
then
npm cache verify
then
npm install -g @angular/cli
I work on Windows 10, sometimes I had to use: npm cache clean --force
as well. You don't need to do if you don't have any problem during the installation.
npm install -g @angular/cli
npm install -g @angular/cli@latest
ng --version
See documentation.
To update Angular CLI to a new version, you must update both the global package and your project's local package.
Global package:
npm uninstall -g @angular/cli
npm cache clean
# if npm version is > 5 then use `npm cache verify` to avoid errors (or to avoid using --force)
npm install -g @angular/cli@latest
Local project package:
rm -rf node_modules dist # use rmdir /S/Q node_modules dist in Windows Command Prompt; use rm -r -fo node_modules,dist in Windows PowerShell
npm install --save-dev @angular/cli@latest
npm install
Source: Github
Source: Stackoverflow.com