Forem

Cover image for How to remove node_modules?
collegewap
collegewap

Posted on • Edited on • Originally published at codingdeft.com

25

How to remove node_modules?

Have you ever got weird errors from npm and were suggested to delete node_modules directory and run npm i?
We will see different ways in which we can delete node_modules from your project.

Deleting a single node_modules folder

You can delete the node_modules folder inside a single project by navigating to that project in the command prompt and
running the following command (use Powershell or Git Bash if you are using windows):

rm -rf node_modules
Enter fullscreen mode Exit fullscreen mode

You can use the npm package called rimraf to delete the node_modules directory:

npx rimraf node_modules

Enter fullscreen mode Exit fullscreen mode

Listing and deleting multiple node_modules folders

If you want to list all the projects with node_modules, then you can use the following command:

find . -name "node_modules" -type d -prune | xargs du -chs

Enter fullscreen mode Exit fullscreen mode

To select node_modules one by one and delete them you can use the npkill npm package:

npx npkill

Enter fullscreen mode Exit fullscreen mode

You can use the arrow keys to select which node_modules folder you want to delete and delete them.

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (1)

Collapse
 
gaurav_ profile image
Gaurav yadav

I am using windows 11 and due to some reason i am unable to delete node_modules from my angular and react projects i am just a beginner and i was learning them and now i want to delete those dummy projects i made, when i use "npx rimraf node_modules" it gives error -4094 and code "UNKNOWN" i have tried all methods listed on SO and even here but the error persists and i now have like 5-6 such projects which are of no use but i am unable to clear them off my memory pleasee helppp!!

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay