Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm: using 'npm uninstall' vs. just removing the folder

Tags:

npm

I wanted to try grunt-babel, so I opened up a terminal in my Home folder and did npm install --save-dev grunt-babel babel-preset-es2015 according to the plugin's instructions.

I was doing this too hastily, and realized I should probably have done this in my new project folder where I am dabbling with ES6 code. I had not even done npm init in that folder nor in the Home folder from where I executed the install command.

When I do npm uninstall grunt-babel, the preset files are removed but 91 folders of different dependencies remain in the node_modules folder.

Can I simply remove the folder instead of running npm uninstall 91 times?

This guy asked a similar question but none of the answers address his subquestion of just removing the folder: how to uninstall npm modules in node js?

like image 583
pastic Avatar asked Oct 07 '16 14:10

pastic


People also ask

What does npm uninstall do?

Description. This uninstalls a package, completely removing everything npm installed on its behalf. It also removes the package from the dependencies , devDependencies , optionalDependencies , and peerDependencies objects in your package.

How do I completely uninstall npm?

To completely uninstall node + npm is to do the following: go to /usr/local/lib and delete any node and node_modules. go to /usr/local/include and delete any node and node_modules directory. if you installed with brew install node, then run brew uninstall node in your terminal.

Does npm uninstall remove from package json?

Calling the npm uninstall command from the project's directory will uninstall the package and remove the package from the project's package. json file.

How do I uninstall all npm global packages?

If you would like to remove all the packages that you have installed, you can use the npm -g ls command to find them, and then npm -g rm to remove them.


2 Answers

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

  • npm uninstall <name> --save to also delete the dependency from package.json.

  • npm rm <package_name> removes the packages when uninstall not working

  • npm prune <name> (see docs) for extraneous packages and packages that are not listed on the parent package's dependencies list.

If you don't want to uninstall one by one run
rm -rf node_modules && npm cache clean && npm install
It's a good way for being sure the packages you uninstall are no more in the packages json.

Now in 2021 npm uninstall <name> will also removed it from package.json

like image 82
EQuimper Avatar answered Oct 21 '22 16:10

EQuimper


UPDATED answer (2020):

These are all aliases to uninstall: remove, rm, r, un, unlink

And today there is no need for --save flag since it is the default. The same goes for install BTW.

like image 33
eyalyoli Avatar answered Oct 21 '22 14:10

eyalyoli