Search code examples
djangoherokudjango-staticfileswhitenoise

Django's collectstatic ignores a folder in Heroku environment


I'm building a Django+Vue monolith and the release pipeline I'm trying to achieve supposes building the Vue frontend into the static folder of a Django app, running collectstatic and starting the server. Static files are served via WhiteNoise.

It works perfectly on my machine. The built folder ends up in the collected static files destination and its contents get nicely served:

static folder of an appcollected static files

But when hosted on Heroku, everything else gets collected except for this built on the fly folder, it just doesn't end up in the staticfiles even though it's present in the static folder of the app. I made sure that the order of execution was correct and even ran collectstatic manually after ensuring that the folder was successfully built.

As you may have noticed, I have this folder in .gitignore, but I've tried removing it from there to no avail.

What could be the reason for such a strange behavior?

p.s. Setting DEBUG to True and serving static files through Django's development server results in a working application, which once again proves the files are in their correct places.


Solution

  • Turns out, I just needed to change the order of the buildpacks so that the NodeJS buildpack runs before the Python one.

    You can read about setting the order of the buildpacks here: https://devcenter.heroku.com/articles/using-multiple-buildpacks-for-an-app