How to delete node_modules folder on Windows machine?
Due to its folder nesting Windows can’t delete the folder as its name is too long. To solve this, install RimRaf:
npm install rimraf -g
and delete the node_modules folder easily with:
rimraf node_modules
edit: If you happen to get an “error” like this:
C:\Users\Nikola\Desktop>npm install -g rimraf C:\Users\Nikola\AppData\Roaming\npm\rimraf -> C:\Users\Nikola\AppData\Roaming\npm\node_modules\rimraf\bin.js npm WARN unmet dependency C:\Users\Nikola\AppData\Roaming\npm\node_modules\generator-ionic requires cordova@'^4.2.0' but will load npm WARN unmet dependency C:\Users\Nikola\AppData\Roaming\npm\node_modules\cordova, npm WARN unmet dependency which is version 5.1.1 npm WARN unmet dependency C:\Users\Nikola\AppData\Roaming\npm\node_modules\bower\node_modules\bower-registry-client requires request@'~2.51.0' but will load npm WARN unmet dependency undefined, npm WARN unmet dependency which is version undefined npm WARN unmet dependency C:\Users\Nikola\AppData\Roaming\npm\node_modules\bower\node_modules\fstream-ignore requires fstream@'^1.0.0' but will load npm WARN unmet dependency undefined, npm WARN unmet dependency which is version undefined npm ERR! peerinvalid The package node-inspector does not satisfy its siblings' peerDependencies requirements! npm ERR! peerinvalid Peer [email protected] wants node-inspector@~0.7.0 npm ERR! System Windows_NT 6.1.7601 npm ERR! command "C:\\NodeJS\\\\node.exe" "C:\\NodeJS\\node_modules\\npm\\bin\\npm-cli.js" "install" "-g" "rimraf" npm ERR! cwd C:\Users\Nikola\Desktop npm ERR! node -v v0.10.36 npm ERR! npm -v 1.4.28 npm ERR! code EPEERINVALID npm ERR! npm ERR! Additional logging details can be found in: npm ERR! C:\Users\Nikola\Desktop\npm-debug.log npm ERR! not ok code 0
Don’t panic :), just try to run rimraf instead, as noted above. In most cases, all will be okay and you’ll be able to use it without a problem. If not, head to the comments, and we’ll take care of it together! For those who don’t care much about comments, here’s the post in which I address this node-inspector issue.
How to delete node_modules folder on Windows machine? http://t.co/0pV4OSTG1L #nodejs #windows #node_modules
— Nikola Brežnjak (@HitmanHR) July 28, 2015
That worked, thanks!
I’m glad this helped you!
Thank you
I made a script to help with cleaning up node_modules folder:
https://github.com/studio174/node-cleanup
And how is your script different from what rimraf does?
Thank you very much, that tool helped me save my time, I’ve already lost a day while searching to delete long paths
You’re welcome. Yeah, I was baffled about this for some time too…
Thanks!! 😀
No problem, glad it helped!
Many thanks, this saved my sanity!
You’re welcome! Yep, it got me saying not so nice things too until I found out the solution 🙂
thank you !
You’re welcome!
Thank You 🙂
You’re welcome. Btw, I browsed through your personal site – looks cool!
TY JESUS.
Glad it helped! 🙂
Thank you! This was driving me insane. This is a fantastic way to remove the dreaded node_modules directory on windows 8.
Thanks Thomas, glad I helped!
Thank you a lot! It’s really usefull!
I’m glad this helped you!
Thank you. I waded through some epic pages suggesting some esoteric solutions to this problem. This worked a treat.
Thanks pollo,
I’m glad it helped!
Worked as a charm.
Thanks
Thanks Guilherme, great it worked for you!
Muito bom, obrigado!
Não tem de quê!
Thanks a million for this, wasted a lot of time till I used this. Thanks once again!!
Hey Rupert, no probs – I’m glad you got it solved!
thank you so much
i was confused how should i delete a long pah 😉
You’re welcome Milad!
Fantastic, thank you.
You’re welcome Jeff!
Does not help me. I’ve installed rimraf and then go to the folder containing node_modules and wrote rimraf node_modules… and nothing happens. Cursor is just blinking…
When I’m trying to do the same using TotalCommander – it says that some files cannot be deleted.
When I go to the deepest level of the node modules and try to delete the last one with rimraf – it throws an error – EPERM and asks me to unlink package.json file
From what I Googled, I found this: https://github.com/isaacs/rimraf/issues/21
Works, thanks! 🙂
You’re welcome, I’m glad it helped!
I always use Long Path Tool to get rid of source path errors. It not free but affordable for anyone.
And rimraf is free. Free as in beer.
Thank You ! , this was really helpful
Thanks, I’m glad it helped!
lifesaver!
Glad to hear that!! I like being the life saver! 😉
You can try Long Path Tool because it works for me.
Thanks bro
You’re welcome!
Many thx man!
My hero! Thanks!
Thank you, I’m glad it helped! I can go around my town saying that I’m Batman :D, since I’m at least someone’s hero 🙂
Thanks a lot …
You’re welcome.
I have some problems after changing one file:(
module.js:96
throw e;
^
SyntaxError: Error parsing C:\Users\User\AppData\Roaming\npm\node_modules\npm\node_modules\semver\package.json: Unexpected token
in JSON at position 511
at Object.parse (native)
at readPackage (module.js:92:52)
at tryPackage (module.js:102:13)
at Function.Module._findPath (module.js:186:20)
at Function.Module._resolveFilename (module.js:467:25)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object. (C:\Users\User\AppData\Roaming\npm\node_modules\npm\lib\utils\unsupported.js:2:14)
at Module._compile (module.js:570:32)
So now I can’t do anything with npm
Probably your best bet would be to reinstall Node.
Thanks Nikola for fast respond. Worked together with rm -rf of npm & npm-cache I had. I changed the path to new npm folder also.
Btw. Can you be helpful with this issue? ‘”C:\Users\User\.bashrc.bat”‘ is not recognized as an internal or external command, operable program or batch file.
I tried pasting the same path in system path, but it’s still providing me the same response?
Sure, it means that you don’t have this file .bashrc.bat on your computer. Or, at least, not in this folder ‘C:\Users\User’ – sound to me like you copied this from somewhere as it doesn’t sound to be a normal Windows Users folder path.
Thanks so much, fixed finally)
GREAT, neat !!! thanks Nikola !
You’re welcome!
I deleted nodejs from my system because it was causing me problems, then re-installed it. But npm is still not working (it wasnt before, which is why i deleted node previously. I have downloaded rimraf and opened it in vscode but cant do npm install. How do i use it to remove node_modules from /npm ?
I managed to get it done after another node re-install, but still didnt get /appdata/roaming/npm/node_modules deleted. But it helped me delete the node_modules which somehow found its way into users/user/git/usr/local/node_modules. Son, one down 🙂 one more to go 🙁
Any suggestions welcome
To be honest, you got me confused – how exactly were you using rimraf? You should be using it from the Command line/Terminal, and not vscode. If for some reason it turns out it can’t remove some dir – I would restart the computer and try again (seriously, not joking).
In all honesty, i have used command line, powershell and vscode (last). I probably got it wrong somewhere along the line. Will definitely try again at some point. Thanks for coming back to me 🙂
Thanks!
I had this problem too and used Long Path Tool and it was so helpful