Skip to content
node

How to remove node_modules?

Jun 1, 2024Abhishek EH1 Min Read
How to remove node_modules?

Have you ever got weird errors from npm and were suggested to delete node_modules directory and run npm i? We will see different ways in which we can delete node_modules from your project.

Deleting a single node_modules folder

You can delete the node_modules folder inside a single project by navigating to that project in the command prompt and running the following command (use Powershell or Git Bash if you are using windows):

1rm -rf node_modules

You can use the npm package called rimraf to delete the node_modules directory:

1npx rimraf node_modules

Listing and deleting multiple node_modules folders

If you want to list all the projects with node_modules, then you can use the following command:

1find . -name "node_modules" -type d -prune | xargs du -chs

To select node_modules one by one and delete them you can use the npkill npm package:

1npx npkill

You can use the arrow keys to select which node_modules folder you want to delete and delete them.

Do follow me on twitter where I post developer insights more often!

Leave a Comment

© 2024 CodingDeft.Com