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

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.