Trying to delete a nodeJs project the other day but had a bug with long file names in windows.. so here’s the fix:
Posted by Michael Whelan
Deleting Nested node_modules Folders
When using Node Package Manager (NPM) on Windows, it has an annoying habit of creating massively nested
node_modules folders that exceed the 260 character path length limit. This makes it extremely painful to try to delete and causes problems with most windows tools. In Visual Studio, for example, I cannot
Refresh Folder when I am in a website project (as opposed to a web application project).
Fortunately, the fix is pretty simple.
First, you need to install RoboCopy. If you are on Windows 8, I suggest you use the version from the Windows Server 2003 resource kit as there appear to be issues with the Windows 8 version. Next, create an empty directory and use the RoboCopy mirror flag to mirror the empty directory to the problematic
node_modules folder. You can then delete the empty directory in the normal way. Cunningly, deleting the mirrored directory also deletes the
mkdir new_empty_directory && robocopy new_empty_directory .build /MIR
Credit to toby1kenobi for this clever solution!
Finally, you just have to restore the deleted node packages. From the application directory, just run npm update:
This command will update all the packages listed in the packages.json file to the latest version. It will also install missing packages.