DEV Community

Cover image for How to Delete the node modules Folder on Windows
Raaj
Raaj

Posted on

How to Delete the node modules Folder on Windows

NPMIf you attempt to delete the node_modules folder on Windows, you may have trouble for a variety of reasons. In some cases, for example, the folder nesting within the directory creates folder names that are too long. You might also get the annoying Folder Access Denied message stating, "You'll need to provide administrator permission to delete this folder".

The solution I use is to install RimRaf globally with npm and then use it to delete the folder. RimRaf is an implementation of the UNIX/LINUX command rm -rf for Node, which removes directories and their contents recursively. First, enter this command to install RimRaf from npm:

npm i rimraf

Once it is installed, you can use the following command from within the project directory that contains the node_modules folder.

rimraf node_modulesThat's it! It works and it's easy to remember and execute.

Top comments (1)

Collapse
 
damian_cyrus profile image
Damian Cyrus

Sometimes it is not possible to delete everything. In this case there is most likely a process or application running that blocks the files or folders to delete.

It might be the IDE running a node.js process as a child. In this case kill all node.js processes:

taskkill /im node.exe
Enter fullscreen mode Exit fullscreen mode

Or forced:

taskkill /im node.exe /f
Enter fullscreen mode Exit fullscreen mode

This also helps if some node application was not killed by a stopped or crashed terminal/application.