Answer the question
In order to leave comments, you need to log in
How do you deal with deleting node_modules folders on Windows?
Hello!
Recently I have been using gulp with its wonderful abilities, but from time to time a bunch of folders accumulate in the virtual server folder, which are from completed projects, 5-6 per month, which are already in the repository and there is no point in storing them locally.
The question arises about the need to delete: well, I don’t like unnecessary files.
And then the ambush files that are in the node_modules folder are not deleted, because there is a very gigantic nesting of folders one into another and Windows cannot cope with the deletion by throwing an error that the file name is too long.
Who is dealing with this and how?
Or is it just my problem?
PS: I use Window 8.
Here is the path to the final file:
G:\DEV\OSERV\OpenServer\domains\wdfasdasd\node_modules\gulp-imagemin\node_modules\imagemin\node_modules\imagemin-gifsicle\node_modules\gifsicle\node_modules\bin-build\node_modules\decompress\node_modules\decompress-tar\node_modules\strip-dirs\node_modules\is-
Answer the question
In order to leave comments, you need to log in
Write a batch file for yourself or a task for gulp that recursively goes through the directories and throws them into the root, or use the globally installed flatten-deps package. And also, if you are a Total Commander user, then shift + del almost always deletes everything normally.
By the way, this problem almost always happens with imagemin for all collectors.
The topic has been widely covered on the Internet for a long time, people have long lit a cigarette that not everything is as simple as it seems at first glance, and there is no "silver bullet".
`npm dedupe` is also very good, but also not very good. It's a good idea to do this in every project after `install` or after every dependency change. Otherwise, a smoke break for a day is simply guaranteed. 1.
If a Bash shell based on CygWin is available (if you use Git, most likely it is a bash shell - there is, but not a fact) a solution that lies on the surface:
a plus sign at the end - it’s necessary: automatically drags the completion (translation) of the line, you can replaced by \;
There was also this option:
`RimRaf` - good, but not very good: you can use it either from a script or manually for each project, i.e. before a mass backup can only be used as part of some "preparatory" tool. And yes - there are problems on different specific configurations. "Platform independence" failed. Essentially the same results can be obtained by doing `rm -rf node_modules` in the `bash` shell or `rmdir /S node_modules` in `cmd`, and `rmdir` in most cases will not remember the length of the line, even if there are reasons for this .
#!/bin/bash
delete-all-dep-folders() {
# `-prune` prevents building up lists of `node_modules` inside `node_modules`
find ${1:-.} -type d -name "node_modules" -prune -exec rm -rf '{}' \; -exec echo 'Deleted {}' \;
find ${1:-.} -type d -name "bower_components" -prune -exec rm -rf '{}' \; -exec echo 'Deleted {}' \;
}
You have some kind of recursion, most likely, in the normal state, node_modules should not grow so much.
PS: and use centos, ubuntu or debian, why do you suffer so much
Yes, there is such a problem under Windows. For myself, I found a way out in using the bash terminal from msys2 , maybe the usual cmd will do, but I have nothing to check on now. Strange as it may seem, such deeply nested directories are removed from the terminal.
Alternatively, you can delete this folder through Unlocker, the process is not the fastest, but it always works 100%.
Winda: by the way, I also accidentally found a way for myself. I just go to almost the deepest folder. cut out. I paste on folders 5 above. etc. this operation as opposed to delete or rename works for me. and over time the path becomes short and everything can be removed by shift-del. try)).
I just got an SSD for a long time. and when I restored it (of course, a lot was lost), but those files and folders that remained - some folders were deep deep - that's how I deleted them.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question