in Links, Our Authors

How to remove all local npm packages?

How to remove all local npm packages when you can’t remove packages because the path is to long or because of any other issue.

Open Terminal or Git Bash (which you get when you install Git for Windows), and navigate to folder from which you want to remove npm packages, and run:

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

This will list all node_modules in the current directory and for each package in this list it will run npm uninstall for it.

So now you will have clean node_modules directory.

Share this ...Tweet about this on TwitterShare on FacebookEmail this to someoneShare on RedditShare on Google+Share on LinkedInPin on Pinterest
  • Clement Busschaert

    To be noted that in my case, Git Bash outputs directories with a trailing “/”.
    Had to change the command to

    for package in `ls node_modules`; do npm uninstall ${package%/}; done;

    • Victor Catalin Torac

      thank you so much

    • Daniel Molnar

      Thanks this worked for me too – solus linux

  • Mira Mansikkam√§ki

    This also works (windows):
    for package in `dir node_modules`; do npm uninstall $package; done;