Reputation: 705
I can't for the life of me figure out an easy way to remove packages from node_modules.
I'm following along a tutorial where it tells me to use npm rm <pkg>
, but when I verify that I performed the action correctly, it says that dependencies are still lying around. I looked in my root directory and noticed that although the package was deleted from my package.json, it's still there in my node_modules directory. Why doesn't npm rm <pkg>
actually remove the package like I imagine it's supposed to? What is the other solution? I suppose I can delete my node_modules directory entirely, but that wouldn't work if I had other dependencies/packages that I relied on.
I've tried googling for the answer, but strangely nothing comes up.
Upvotes: 1
Views: 4773
Reputation: 1898
npm uninstall
removes the module from node_modules, but not package.json.
npm uninstall <pkg> --save
will also delete the dependency from package.json.
npm rm <pkg>
removes the packages when uninstall not working
npm prune <pkg>
for extraneous packages
If you don't want to uninstall one by one run
rm -rf pkg-name && npm cache clean && npm install
Upvotes: 4