Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File Explorer takes a long time to delete node_modules #21

Open
nmoinvaz opened this issue Jul 31, 2020 · 32 comments
Open

File Explorer takes a long time to delete node_modules #21

nmoinvaz opened this issue Jul 31, 2020 · 32 comments

Comments

@nmoinvaz
Copy link

nmoinvaz commented Jul 31, 2020

Environment

Item Value
OS, Version / Build 10.0.19041.0 Microsoft Windows NT 10.0.19041.0
Processor Architecture AMD64
Processor Type & Model Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz, 3192 Mhz, 6 Core(s), 12 Logical Processor(s)
Memory 32GB
Storage Type, free / capacity (e.g. C: SSD 128GB / 512GB) SSD 2TB
Relevant apps installed Node.JS / NPM

Description

When working on a project that utilizes package manager npm, it creates a node_modules directory that contains at least 100,000 files. On larger projects it can be even more. Deleting the node_modules directory from File Explorer takes a long time, and some times it goes through capturing all the information about the files and fails on some further steps.

nodemodules4

Often times File Explorer is the first way that users and developers go to delete files. Only after File Explorer fails do they then have to result to a command prompt. It is quite annoying to have to drop to a command prompt just for this folder. I know I can't be the only developer who experiences this problem.

For a comparison, this is how long it takes to delete the folder on macOS:

nodemodules3

I realize that both operating systems do different things behind the scenes, but it is unlikely that I can believe that nothing can be done to improve the experience with deleting folders that have lots of files.

Steps to reproduce

  1. Must have npm project already (you can try CRA for example)
  2. npm run install
  3. Open file explorer and delete node_modules

Expected behavior

It should not take so long to delete all the files.

Actual behavior

It takes a significant amount of time. File Explorer goes through various steps of calculating time, etc, after which it presents an UAC dialog, and then another permissions dialog at which point I end up just canceling.

Suggestions

  • It should recognize that the folder has many files and present an option to the user asking if they want "quick delete" the folder because it has too many files. In this instance File Explorer might choose to not notify all other apps that each individual file is being deleted, only that the main directory is being deleted.
  • Delete the folder immediately, and notify all apps of file deletes in the background.
@wolfmanfp
Copy link

wolfmanfp commented Aug 3, 2020

It also happens when you copy a Node.js project from an SSD to a USB drive, it could even take half an hour.

@BrandonLive
Copy link

BrandonLive commented Sep 18, 2020

One tip that can help here: Hold Shift when you invoke the delete command (whether from keyboard or via the menu). This will invoke the permanent delete flow, rather than moving everything to the recycle bin. It should usually be near instantaneous.

Of course, make sure you really want to delete things before using this approach :-)

@nmoinvaz
Copy link
Author

I ran a test to see the experience when using shift+delete. The experience is a bit better but it still takes a ton of time even when deleting permanently.

nodeshiftdel

When deleting files normally, Windows Explorer will enumerate all the files and see if the file sizes are too big to be recycled. If they are too big to be recycled Explorer will prompt asking if you want to permanently delete them. I think that a change could be made to Windows Explorer, that if it detected 10,000+ files it would ask if you want to permanently delete them as the delete operation could take a lot time. But even if Explorer had this change the delete option is no where near the speed it is on macOS.

@orcmid
Copy link

orcmid commented Sep 19, 2020

I think I have very little skin in this particular game. I simply don't go there with projects and my projects are usually pretty small, befitting the size of my brain.

At the same time this strikes me as a kind of micro-managed compensation for badly-architected source, build structures, and out-of-control dependencies. I wonder what is served by pandering to that.

Now, I have been thinking that since pre-compiled headers and the ugliness of windows.h, so you can calibrate my attitude from that. I will now stifle myself for a few more years.

@Eli-Black-Work
Copy link

Eli-Black-Work commented Apr 14, 2021

Taking another look at this, it feels like the most actionable of the original suggestions is this one:

  • Delete the folder immediately, and notify all apps of file deletes in the background.

I wonder if that would really speed things up? Seems like a nice idea, if so 🙂

@aminya
Copy link

aminya commented Apr 28, 2021

I recommend using fastcopy. It is much faster than Windows Explorer when it comes to doing operations on a large number of files.

image

It also happens when you copy a Node.js project from an SSD to a USB drive, it could even take half an hour.

When copying a large number of files to a slow USB drive, consider compressing the folder before copying.

@crediblebytes
Copy link

This should have way more traction. It takes more time to delete the folder than it does to run npm install, pull down all the packages and install them! Is this because all the files are not stored contiguously?

@nathantaal
Copy link

Plus one for this issue

@mswezey23
Copy link

Been experiencing this issue for years now. As much as I love slingin code on Windows, this kills it for me...

@robertkraig
Copy link

This is not just an issue with windows. I use a macbook pro 2015 w/ 16gb of ram. Also takes forever to delete a node_modules folder. I believe my experience was significantly faster on linux than either macos or windows. But macos ssd is not nearly as fast as you'd expect.

@mswezey23
Copy link

This is not just an issue with windows. I use a macbook pro 2015 w/ 16gb of ram. Also takes forever to delete a node_modules folder. I believe my experience was significantly faster on linux than either macos or windows. But macos ssd is not nearly as fast as you'd expect.

I daily a MacBook Pro (2019, and now a 2020) and never had any issues with node_modules. Granted mine isn't 2015.

I also, for a brief period, had a previous gen Mac Mini that I upgraded its spinning rust to a (still on sata) SSD. Still magnitudes faster than a current day Windows machine running on a pcie (nvme) SSD attempting to delete a node_modules folder.

@schmorrison
Copy link

In my case occasionally I need to delete node_modules to reinstall all packages. Instead of deleting node_modules directly I do the following:

~$ mv node_modules node_modules.del
~$ npm i 

And from the VSCode/File Explorer I Delete < node_modules.del

This way the packages can install under node_modules while node_modules.del is deleted. The deletion process is not quicker, but the reinstall can take place simultaneously. VSCode might complain about too many files to index until the folder is deleted if reinstalling at the same time.

@1mike12
Copy link

1mike12 commented Sep 23, 2021

I have nothing to add other than this has been something that's bothered me for so long but I've only just started to consciously look into it since working on a large project with a larger node_modules than before. rm -rf ing on a crappier macbook 3 years older should not be an order of magnitude faster than on windows.

@chrisribe
Copy link
Member

Funny how and small project like https://fastcopy.jp/ can do it better than what windows can....
Especially on shift + delete, you would expect the same speed uggh :(

@Khalilolgod
Copy link

try rm -Recurse -Force .\node_modules\ in powershell inside the project directory.

@zackpi
Copy link

zackpi commented Apr 22, 2022

4min 30sec - "Shift+Delete" aka "Permanently Delete"
45sec - "rm -Recurse -Force .\node_modules"
16sec - "rimraf .\node_modules"

An added benefit is that rimraf is cross-platform 😃

For comparison, I also have an M1 macbook, and running "rm -rf .\node_modules" takes about 15sec, so likely this is as good as it'll get

@j471n
Copy link

j471n commented Apr 27, 2022

Use rmdir node_modules in Powershell inside the project directory.

@jahidhassan2424
Copy link

jahidhassan2424 commented Jun 3, 2022

It also happens when you copy a Node.js project from an SSD to a USB drive, it could even take half an hour.

just delete the node_modules folder then copy it. Copying process will be completed in a dew second. Then in the new location simply run "npm i". Note: you wont loosew any folder in node_modules. All of your dependencies will be downloaded with the command "npm i""

Second Option you can try: create zip file of that folder containing node_modules then copy it. But option 1 is more efficient.

@Jogai
Copy link

Jogai commented Nov 15, 2022

Fastest way for me is:

del /f/s/q node_mdules > nul
rmdir /s/q node_modules

Got it from https://stackoverflow.com/a/6208144/141243

@ikluhsman
Copy link

Fastest way for me is:

del /f/s/q node_mdules > nul
rmdir /s/q node_modules

Got it from https://stackoverflow.com/a/6208144/141243

This does not resolve the issue, it produces the same behavior as described in the original report.

@Jogai
Copy link

Jogai commented Mar 13, 2023

Fastest way for me is:

del /f/s/q node_mdules > nul
rmdir /s/q node_modules

Got it from https://stackoverflow.com/a/6208144/141243

This does not resolve the issue, it produces the same behavior as described in the original report.

Its an alternative. And it can't produce the same behavior, because instead of the file explorer its using a cmd window. Totally different UI.

@chrisribe
Copy link
Member

Fastest way for me is:

del /f/s/q node_mdules > nul
rmdir /s/q node_modules

Got it from https://stackoverflow.com/a/6208144/141243

It's a valid solution, just wish Microsoft would run that via the file explorer UI to avoid the long delete times.

@ikluhsman
Copy link

ikluhsman commented Mar 14, 2023 via email

@Jogai
Copy link

Jogai commented Mar 14, 2023

Yes it does, see https://superuser.com/a/289399/471565

@taleleuma
Copy link

taleleuma commented Mar 24, 2023

Fastest way for me is:

del /f/s/q node_mdules > nul
rmdir /s/q node_modules

Its an alternative. And it can't produce the same behavior, because instead of the file explorer its using a cmd window. Totally different UI.

Above solution is faster but not the fastest (compared to Mac or Linux). Kind of hacked solution. Plus, its not user-friendly and very risky to use on daily basis. Imagine, you copy-pasted del /f/s/q * > nul command on a wrong folder, say a default folder when you open command prompt. Your lose your windows user profile.

@xieyezi
Copy link

xieyezi commented Sep 4, 2023

Is there any other way to solve this problem? Such as one cli or plugin?

@xieyezi
Copy link

xieyezi commented Sep 4, 2023

4min 30sec - "Shift+Delete" aka "Permanently Delete" 45sec - "rm -Recurse -Force .\node_modules" 16sec - "rimraf .\node_modules"

An added benefit is that rimraf is cross-platform 😃

For comparison, I also have an M1 macbook, and running "rm -rf .\node_modules" takes about 15sec, so likely this is as good as it'll get

I found that rimraf is really much faster, thanks

@batzen
Copy link

batzen commented Oct 16, 2023

You could also try using my tool to delete.
It should be much faster than the other tools.
Grab it from here https://github.com/batzen/Batzendev.Tools/releases/tag/v6.0.0 or install via chocolatey choco install batzendev.tools.
Feedback is appreciated.

@Jogai
Copy link

Jogai commented Oct 17, 2023

@batzen on your website it says that the tool is MIT licenced, but where is the actual source?

@batzen
Copy link

batzen commented Oct 17, 2023

MIT doesn't require published sources.
It's a private hobby project and I don't want to deal with all the overhead that comes with going OSS. I have enough OSS projects where I have to deal with all that. 😉
So the tool is free, but not OSS.

@wassimmohamed
Copy link

@StefanSpeterDev
Copy link

del /f/s/q node_mdules > nul

This absolutly did the trick and what INSTANT !
Thank you.
Also, if you want to use it on a Powershell terminal, use this command :
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue node_modules
It will delete the whole folder and you don't need to run the second command.
Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests