101

Angular 6 has new CLI command ng add <package>.

How can I remove the package using Angular CLI?

UPDATE

documentation

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.

Dmitry Grinko
  • 13,806
  • 14
  • 62
  • 86

5 Answers5

180

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.

Nour
  • 5,609
  • 3
  • 21
  • 24
  • Yes i do, ng add will use package manager to run the install script and edit your angular.json file, but npm install will only install the package. – Nour May 12 '18 at 14:27
  • 1
    So you need ng remove command that will edit your configuration again and remove any dependency, css files and javascript files which has included by the ng add command ? – Nour May 12 '18 at 14:30
  • 5
    The `ng help` command show that there is no `ng remove/delete` command. – Nour May 12 '18 at 14:38
  • 97
    Wonder why would some one implement `ng add` and not implement `ng remove`! – James Poulose Oct 20 '18 at 02:30
  • 2
    run the install script and **edit your angular.json file** <- This is the problem. npm uninstall is not a perfect solution – tom10271 Jan 17 '20 at 02:24
8

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.

Daniel Danielecki
  • 8,508
  • 6
  • 68
  • 94
2

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

Vallerious
  • 570
  • 6
  • 13
1

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.

enter image description here

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
virus_dmk
  • 89
  • 6
0

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

TylerH
  • 20,799
  • 66
  • 75
  • 101
Nicu
  • 3,476
  • 4
  • 23
  • 43