If you use node on windows the chances are that you've come across the following error when trying to delete the node_modules directory or any of its parent directories.

The specified path, file name, or both are too long

or

The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.

I previously used various hacks to get round this, including;

robocopy new_empty_directory node_modules /MIR

Which creates an empty mirror directory that you can then delete.

However, I recently came across the node module rimraf, created by NPM founder Isaac Schlueter. Annoyingly this project first started in Feb 2011 which means ive had a few years of unnecessary hurt but that doesn't necessarily mean you have too! :)

Check the projects wiki out for better documentation but generally all you will have to do is the following.

Install globally.

npm install rimraf -g

Then

rimraf .\node_modules\

will recursively remove all modules and its dependencies.

Thanks for reading.