How To Exclude node_modules Directory When Running collectstatic Command in Django

21 Jun · by Tim Kamanin · 1 min read

If you use npm or yarn to install frontend packages inside your Django project, you may notice, that when you run python collectstatic command, it ends up collecting huge amounts of files.

That's because by default, collectstatic grabs all content of static directories inside the project, including thousands of files that live inside node_modules directories produced by npm and yarn.

Luckily, it's straightforward to omit node_modules directories altogether; just run your collectstatic command with an additional "ignore" argument, like this:

python collectstatic -i node_modules

And you're done!

P.S. If you're tired of typing python everytime you need to run Django command, I recommend you to check a little package of mine called "Django anywhere":, it'll surely save you some keystrokes here and there.

Want to get more 🔥 tips like this one?

Subscribe to get notified about new dev tutorials