How to remove package using Angular CLI?
AngularAngular CliAngular Problem Overview
Angular 6 has new CLI command ng add <package>
.
How can I remove the package using Angular CLI?
UPDATE
> ng add
will use your package manager to download new dependencies and invoke an installation script (implemented as a schematic) which can update your project with configuration changes, add additional dependencies (e.g. polyfills), or scaffold package-specific initialization code
It is not the same npm install <package>
I was trying to use ng rm
but it is not working yet.
Angular Solutions
Solution 1 - Angular
You can use npm uninstall <package-name>
will remove it from your package.json file and from node_modules.
If you do ng help
command, you will see that there is no ng remove/delete
supported command. So, basically you cannot revert the ng add
behavior yet.
Solution 2 - Angular
It's an open issue #900 on GitHub, unfortunately at this point of time it looks that in Angular CLI there's nothing like ng remove/rm/
..., only using npm uninstall DEPENDENCY
is the current workaround.
Solution 3 - Angular
Sometimes a dependency added with ng add
will add more than one package, typing npm uninstall lib1 lib2
could be error prone and slow, so just remove the not needed libraries from package.json
and run npm i
Solution 4 - Angular
I don't know about CLI, I had tried, but I couldn't. I deleted using IDE Idea history.
If You use an Intellij Idea, just open History changes.
Tap by main folder of the project -> right click -> local history -> show history.
Then from top to bottom revert changes.
Solution 5 - Angular
With the cli I don't know if it's a remove command but you can remove it from package.json and stop using it in your code. If you reinstall the packages you will not have it any more
Solution 6 - Angular
the NPM uninstall @angular/material has worked for me, deleted the custom folder by mistake and then just ran ng add @angular/material
Solution 7 - Angular
I think best approach until Angular team add this feature to cli is first create angular (ng new something) in other place and then add what you want to delete. Using git to check witch files are changed or added by angular cli. then you can revert that changes.
Be careful of untracked files from .gitignore
.
Solution 8 - Angular
if you are using version control you can revert to commit before you did ng add <package>
. Like git checkout -f
if you didn't commit yet.
Solution 9 - Angular
npm uninstal @angular/material
and also clear file custom-theme.scss