How to remove unwanted packages from node_modules? npm rm doesn't work

67
June 04, 2021, at 09:30 AM

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.

Answer 1

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

npm uninstall --save to 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
READ ALSO
How to view logs of custom process event listeners in jBPM

How to view logs of custom process event listeners in jBPM

I have created a custom process listener, deployed to a project and ran the project

69
MySQL database-dump import

MySQL database-dump import

I need some details on importing and exporting a MySQL 8 database

90
reactjs with material ui - appbar doesn&#39;t support gradients

reactjs with material ui - appbar doesn't support gradients

I created my own appbar for my own selfproject, and i also use Erica One fontI just started the project so there is not enough code anyway

93
Finding the index position of strings in the column [closed]

Finding the index position of strings in the column [closed]

Want to improve this question? Update the question so it's on-topic for Stack Overflow

71