Reputation: 666
I've been getting the error "MIME type ('text/html') is not a supported stylesheet MIME type" on my django+react deploy on Heroku. This is mostly because django can't find the staticfiles from react.
Setting staticfiles dir in settings.py should have solved the problem, but it didn't:
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'build/static'),
)
Upvotes: 1
Views: 328
Reputation: 666
I decided to create this question with self answer because I spend a very long and frustrating afternoon solving this issue since I didn't find the right solution anywhere on the web.
What I did wrong in my deployment was setting my buildpacks the wrong way when I set up the project for heroku. Don't be me and immediately go to StackOverflow and find the solution there.
To serve the staticfiles correctly obviously python and collectstatic has to run after npm build from react. Thus add python buildpack after nodejs in Heroku:
heroku buildpacks:add --index 1 heroku/nodejs
heroku buildpacks:add --index 2 heroku/python
Upvotes: 1