How to Delete the node_modules Folder on Windows

Posted on Dec 31, 2019

If 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" (shown below).

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 install rimraf -g

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

rimraf node_modules

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