5
votes

Explanation : There are about 15 subfolders in the node_modules directory.When going to perform any operation(deleted, moved or renamed) it popup below message.

Error message:

The source file name(s) are larger than is supported by the file system. Try moving to a location which has a shorter path name, or try renaming to shorter name(s) before attempting this operation.

Screenshot : enter image description here

sub folder inside npm_modules directory.

node_modules\gulp-connect\node_modules\gulp-util\node_modules\dateformat\node_modules\meow\node_modules\normalize-package-data\node_modules\validate-npm-package-license\node_modules\spdx-expression-parse\node_modules\spdx-license-ids\spdx-license-ids.json

Tried so far:

I also tried to delete the folder(node_modules) using command prompt using command rmdir <dirname> /S but did not work as well.

enter image description here

There is a way to do this is that go into subfolder after subfolder, renaming each folder to something short like 'b'. Eventually the path is short enough to allow deletion. This will waste quite a bit of time.

Is there any efficient way to delete this node_modules directory.
Any immediate help will be highly appreciable. Thanks

2

2 Answers

11
votes

Newest versions of npm fix this issue flattening the path: https://github.com/npm/npm/issues/3697.

Try

D:\vms\fe> robocopy d:\path\to\temp\dir node_modules /purge

to remove the nested dirs.

Update

As pointed by Rohit Jindal, another option is use rimraf util (which basically calls rm -rf):

> npm install -g rimraf
> rimraf node_modules
0
votes

For the record, and because of the release of a newish open-source project released by Microsoft, you can easily delete paths that are too long using WinFile (which was introduced in WinXP). Sometimes you have to go "Back to the Future". This can delete paths too long on Microsoft networks share as well.

enter image description here

WinFile (compiled for Win10) available here https://github.com/Microsoft/winfile

To find many paths that are too long and automate a fix, I recommend Path Too Long Auto Fixer - a free demo is available.