How To Exclude node_modules Directory When Running collectstatic Command in Django

Jun 21, 2017 · Updated: Jul 12, 2021 · by Tim Kamanin

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.

Hey, if you've found this useful, please share the post to help other folks find it:

There's even more:

Subscribe for updates

  • via Twitter: @timonweb
  • old school RSS:
  • or evergreen email ↓ ↓ ↓