Three Ways To Delete node_modules Directory or Any File Name Too Long Folders


If you have worked with Windows development or using Windows as a platform to do development work for other applications, like node.js. You will at some point encounter the issue of “File Name Too Long” error, specifically when your absolute path is exceeding 260 characters, Windows doesn’t let you delete the directory or file.

file name is too long thumb - Three Ways To Delete node_modules Directory or Any File Name Too Long Folders

This is probably one of the oldest legacy issues that are still lingering around in the modern OS, even in Windows 10. One of the biggest problems is when applications or development referencing via a relative path, it doesn’t have a context on how long the absolute path is, it becomes a problem when trying to delete any directory that are longer than 260 characters. This is particularly common when doing node.js development on Windows. Because it’s a cross-platform framework, other OS, like Linux and Mac OS X doesn’t have this restriction. So developer from another platform, might not have this mindset to shorten the directory name so any poor Windows developer would have an easier time to work with the tool. If you’d like to find more info on the history and the reason behind this odd 260 number, you can check out a detailed Windows API documentation that explains all the technical details behind.

Method One: Directory Renaming

So we know the root cause of the problem, a very dumb way to fix it is to rename all the directory to be shorter and fix the limit. However, before you think this is a stupid idea (it is), if all you need is to rebuild node_modules dependencies or any other file path, you only need to change the root directory path. For example,  C:\User\yourname\Documents\project\node_modules\…\…\ can become C:\User\yourname\Documents\project\old_node_modules\…\…\

Method Two: Install Node Package rimraf

Use a tool such as npm rimraf, command line version (CLI) of the utility offers Linux/UNIX rm –rf on Windows. It’s a cross-platform npm utility. You need to have node.js installed and run the following command to install this tool via

npm install rimraf –g

Then navigate to the directory where you’d like to remove the node_modules and run

rimraf node_modules

Method Three: Run Cygwin

Similar to method two where we are leveraging Linux/UNIX command to get stuff done, you can actually run native Linux commands through Cygwin. All you need is download and install basic packages with Cygwin.

Once you have Cygwin installed, launch the command prompt and navigate to the path via “/cygdrive/” directory to locate Windows directories.

2015 12 30 1438 thumb 1 - Three Ways To Delete node_modules Directory or Any File Name Too Long Folders

After successfully located the directory location, you can run

rm –rf node_modules

This will remove all your directory under node_modules silently regardless how long the file name is.


  1. “Long Path Tool” is very helpful for this error !
    You can use to solve this problem

    Long Path Tool help me a lot when i have an issue like file deleting or renaming the file. Also good to use if file name and file extension is too long.

    I used to have similar problems too, but after using “long path tool” everything was solved. Try this software and you would be glad you did.

  2. Use “Long path tool” is very helpful for this problem. You can solve this problem like copy, delete, long path files by using this tool.

  3. Easy solution I found is using 7zip (as I always have it installed) … go to the offending folder and right click to bring up the contect menu. Under 7zip menu click on Add to Archive. Tick the box delete files after compression and click on ok. Zip file will be created but folder will be deleted.


Please enter your comment!
Please enter your name here