Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you uninstall all dependencies listed in package.json (NPM)?

People also ask

How do I uninstall all dependencies and packages?

If you want to uninstall all global packages, then you need to name the packages one by one in the npm uninstall -g command. Run the npm list -g --depth=0 command to list the packages installed globally on your computer. That should uninstall all global packages for you.

How do I remove old dependencies from package json?

To remove a package from the dependencies in package. json , use the --save flag. Include the scope if the package is scoped.


If using Bash, just switch into the folder that has your package.json file and run the following:

for package in `ls node_modules`; do npm uninstall $package; done;

In the case of globally-installed packages, switch into your %appdata%/npm folder (if on Windows) and run the same command.

EDIT: This command breaks with npm 3.3.6 (Node 5.0). I'm now using the following Bash command, which I've mapped to npm_uninstall_all in my .bashrc file:

npm uninstall `ls -1 node_modules | tr '/\n' ' '`

Note: It would remove all dependencies list from package.json and package-lock.json rendering npm install useless as there would be no dependencies listed to be installed.

Added bonus? it's way faster!

https://github.com/npm/npm/issues/10187


This worked for me:

command prompt or gitbash into the node_modules folder in your project then execute:

npm uninstall *

Removed all of the local packages for that project.


For windows go to node_modules dir and run this in powershell

npm uninstall (Get-ChildItem).Name 

I recently found a node command that allows uninstalling all the development dependencies as follows:

npm prune --production

As I mentioned, this command only uninstalls the development dependency packages. At least it helped me not to have to do it manually.