I have been trying to serve my dist files of React frontend app to my Django project. However, the browser keeps refusing to serve static files and throws the error described below:
> Refused to apply style from 'http://localhost:8000/static/my-react-app/assets/index-CgY6hLMH.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
> Refused to apply style from 'http://localhost:8000/static/my-react-app/assets/index-CgY6hLMH.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
> index-LlsxC_Wu.js:1 Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.
Here’s how my Django repository looks:
enter image description here
All my CSS and JS static files are inside assets
while index.html
is the template I want to serve.
My settings.py
file looks like this:
enter image description here
I already tried rebuilding the dist files and copying them to the static directory and made changes to static paths as well but all in vain.
Advait Thakar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.