DEV Community

Cover image for How to remove node_modules?
collegewap
collegewap

Posted on • Originally published at codingdeft.com

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):

rm -rf node_modules
Enter fullscreen mode Exit fullscreen mode

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

npx rimraf node_modules

Enter fullscreen mode Exit fullscreen mode

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:

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

Enter fullscreen mode Exit fullscreen mode

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

npx npkill

Enter fullscreen mode Exit fullscreen mode

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

Top comments (0)