I
I
Igor Pushkarsky2015-07-27 04:21:43
css
Igor Pushkarsky, 2015-07-27 04:21:43

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-

The rest stupidly does not even open.

Answer the question

In order to leave comments, you need to log in

7 answer(s)
D
Defiancefew, 2015-07-27
@RainMEN

npm install rimraf -g
rimraf node_modules

D
Denis Malinochkin, 2015-07-27
@DiAsCrafts

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.

K
Konstantin   , 2017-07-13
@SynCap

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 {}' \;
}

After running the script (you can just copy-paste it into the bash window), you can run the `delete-all-dep-folders` command without parameters in the desired folder or set the path as the first parameter:
Let me remind you: if `bash` is under cygwin, only then it does not care about the length of the path . As far as this is true, you should know for yourself - where and what version of Gita / Bash did you take, you should read there: on the Internet there are a lot of bash versions compiled using native Windows libraries that do not use cygwin !!!
PowerShell . Allegedly the same "silver bullet" from MelkoSoft. It seems that he did not care about the length of the path. Allegedly.
If you saw something else in the documentation / boarding schools, do not rush to refute: nothing is unambiguous with Windows, she (Winda), like any normal woman, has in her dictionary of binary logic (either "yes" or "no") meaning "maybe", "I don't know" and "it's not me".
Option:
Quite working, BUT PowerShell version > 4.0. Older versions, even with the `-Force` option, cannot delete non-empty folders.
Let me clarify: despite the fact that Remove-Item (aka del, aka ...) has the ability to designate filters and work recursively, nevertheless, there is still a need for a pipeline (a stick sign between commands), and this rake has been stepped on there are already a lot of people even before it was recognized and noted on ms-tech and in the documentation that yes, there is a problem and it is proposed to use a pipeline as a solution, i.e. – through a stick it is necessary to do, and not to do stupidly Delete.
And yes, I ran into a case where this did not work - on a USB disk (NTFS) there was an old project on `Meteor`. No relevance, for history, too, is not a godsend, but he was the only one who resisted strongly for more than 4 hours. After that, I got tired of looking for the reasons for such persistence and the good old (honestly bought back in the last century) Total Commander coped with the entire project for 1.897s.
Competition winner - Total Commanderwith disk operations settings using native (NOT system) functions. Do not believe the documentation: Windows, starting with Vista, performs much more "left" actions for beauty during disk operations than Commander, therefore, operations with "his" functions are performed faster than "her" functions. It's quite good if you disable support for directory content description files in the Commander. Also, once upon a time, I came across a plug-in for the commander, which replaced / supplemented the search for files with another one, which uses a different library for working with regular expressions and disk operations can be performed immediately on the search results without shifting to the temporary panel.
Or are we not programmers? We write our bike for recursive bypass of directories and `rimraf` - what they need. At the same time, we do not forget to put this golden key separately, so as not to kill its dependencies in passing, and make a console call for it. We successfully publish in NPM and collect stars on Github. Dare, but I'm a real programmer, I'm too lazy when everything is simple and clear :)

T
Timur Shemsedinov, 2015-07-27
@MarcusAurelius

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

A
Alexey, 2015-07-27
@MAKAPOH

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.

A
Andrey Selivanov, 2017-07-18
@Seland

Alternatively, you can delete this folder through Unlocker, the process is not the fastest, but it always works 100%.

S
Sergey Topolov, 2017-11-29
@topus009

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 question

Ask a Question

731 491 924 answers to any question