Reputation: 564
When I want to delete a node_modules folder it takes ages when I delete it using Windows Explorer. How do I delete faster?
Upvotes: 8
Views: 13302
Reputation: 21
Running the command Remove-Item -Path "directory_or_file_path" -Recurse -Force
instantly delete node_modules for me on VSCode. How to Delete Node Modules in VSCode?
Upvotes: 1
Reputation: 330
I use to have the same issue, taking hours to achieve the deletion until I found this workaround:
Select the node_modules folder. Do this with the file explorer.
Open Powershell as admin: press Alt+F, then S, then A.
Wait and accept to open Powershell as admin
Paste this command and press Enter: del /f/q/s *.* > nul
.
WARNING
Please be sure to be in the folder node_modules
. I mean, that the terminal path ends with ...\node_modules
.
In the above command, we use the
/f
switch to force the deletion of read-only files. The/q
switch enables quiet mode. The/s
switch executes the command for all files in any folder inside the folder you’re trying to remove. Using*.*
tells the del command to delete every file and> nul
disables the console output improving performance and speed.
Wait for the process to take action.
Now go up one level in the directory with cd..
.
Finally use this command to delete the node_modules folder rmdir /q/s node_modules
In the above command, we use the /q switch to enable quiet mode, the /s switch to run the command on all the folders, and
node_modules
is the variable you need to specify to delete the folder you want.
If you get an error with Powershell try other terminals as administrator like Windows Terminal, Command Prompt (cmd) or third party terminals like ConEmu. I made this steps with Cmder and all the deletion was done in just 5 minutes. Off course this duration is variable according to the size of the folder.
References:
Upvotes: 6
Reputation: 564
From you project folder use following command to delete it:
rd .\node_modules\ /s /q
Upvotes: 2