I'm working on angular-cli 1.0.4 in existing project, I would like to update the version to 1.2.4. What is the best way to uninstall the old one and update to the newer one using npm with effecting my existing project? which updates the version on package.json file.
3 Answers
Look at the Angular-Cli docs. You don't need to create a new project.
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 1 Comment
rmdir /S/Q node_modules distUpdating minor version of AngularCLI v.1.x.x
NOTE: If you are updating to 1.0 from a beta or RC version, check out the 1.0 Update Guide.
AngularCLI doesn't have support for automatic update of the CLI version and the dependencies on existing projects. However, keeping up to the latest version can be quite beneficial as you get the latest features, performance improvements and bug fixes.
I managed to successfully update my project from v.1.1.0 to v1.3.0 with the following steps:
- Update the version of the global AngularCLI (follow the steps in this guide)
Create an 'upgrade-project' with the latest version that you recently installed
$: ng new upgrade-project --skip-installThis will create the project in new folder and commit the initial files.
Create and apply an upgrade patch with Git
You can use plain git format-patch / apply or the support of your favorite IDE (ex. WebStorm)
$: git format-patch -1 HEAD --stdout > cli-upgrade.patch $: git apply cli-upgrade.patchCarefully go through the changes and verify which of them are really needed
NOTE: you will need to merge the modified files correctly
Re-install the updated dependencies
clear the old dependencies before the re-install [recommended]
$: rm -rf node_modulesinstall the dependencies
$: npm install
Now your update is complete, the next step is to verify that everything is working as expected and fix small things that might got broken along the way
After the CLI was successfully updated together with it's initial dependencies feel free to update also your additional dependencies which are not installed by default (ex. Angular Material).
$: npm update @angular/material ... Comments
Both answers above are correct and are based on the same approach that is the de-facto way as of today.
There are plans from Angular CLI to add an update feature in one of the coming releases.
To update your additional dependencies there is an elegant way by moving them to a second package.json. You can use Yarn Workspaces or package-json-merge for that. More info on my website: https://www.rainerhahnekamp.com/en/updating-angular-cli-dependencies/
1.0.4to1.2.4but only how to reinstall/update the@angular/cli npmpackage in the project