node.js - working - uninstall npm windows




How to uninstall npm modules in node js? (10)

As commonly known, any npm module can be installed by running a simple command: npm install <module_name>.

I have installed a few modules that I do not use anymore and I just want to get them off. I have a few questions regarding this:

  • Do we have any command or process to uninstall a module from the root (something like npm uninstall <module_name>) or will simply removing the module files do?

  • How does it affect us if we keep the unused modules?


Additionally, if you've started using yarn, in place of npm:
yarn remove <package-name>

Is the equivalent of:
npm uninstall <package-name> --save

This will
- remove the package from package.json, as well as
- uninstall it from your project's node-modules folder


For Windows Users - If you want to remove all the node modules installed at once:

  • Open powershell
  • Go inside node_modules folder (cd node_modules)
  • Run this command - "npm uninstall (Get-ChildItem).Name"

It will uninstall all the modules.


I just install stylus by default under my home dir, so I just use npm uninstall stylus to detach it, or you can try npm rm <package_name> out.


If it doesn't work with npm uninstall <module_name> try it globally by typing -g.

Maybe you just need to do it as an superUser/administrator with sudo npm uninstall <module_name>.


Sometimes npm uninstall -g packageName doens't work.

In this case you can delete package manually.

On Mac go to folder /usr/local/lib/node_modules and delete folder with package you want. That's it. Check your list of globally installed packages with this command npm list -g --depth=0


The uninstall option didn't work for me when I tried to use the same command to the one I used in installing (as I was installing with the @latest directive)

So for example, I installed a package like this:

npm install  @ngtools/[email protected]

And then I wanted to uninstall it so I used the same command (including @latest)

npm uninstall  @ngtools/[email protected]

So the above uninstall didn't work, I have to remove the @latest & then it worked well

npm uninstall  @ngtools/webpack

I hope this helps


The command is simply npm uninstall <name>

The nodejs documents https://npmjs.org/doc/ have all the commands that you need to know with npm.

A local install will be in the node_modules/ directory of your application. This won't affect the application if a module remains there with no references to it.

If you're removing a global package however, any applications referencing it will crash.

Here are different options:

npm uninstall <name> removes the module from node_modules, but not package.json

npm uninstall <name> --save also removes it from dependencies in package.json

npm uninstall <name> --save-dev also removes it from devDependencies in package.json

npm -g uninstall <name> --save also removes it globally


To remove packages in node_modules/ in bulk, you could also remove them from package.json, save it, and then run npm prune on the terminal.

This will remove those packages, which exist in the filesystem, but are not used/declared package.json.

P.S> This is particularly useful on Windows, as you may often encounter problems with being unable to delete some files due to the "exceeded path length limit".


Use npm uninstall <packageName> --save to uninstall a package and remove it's entry in package.json.

npm uninstall -g <packageName> --save will uninstall the package if it was added globally.


Well to give a complete answer to this question, there are two methods: (for example we call the installed module as module1)

  1. To remove module1 without changing package.json:

    npm uninstall module1

  2. To remove module1 with changing package.json, and removing it from the dependencies in package.json:

    npm uninstall --save module1

Note: to simplify the above mentioned commands, you can use -S instead of --save , and can use remove, rm, r, un, unlink instead of uninstall





npm