Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to load module script

After deploying an Angular app on Heroku, a blank page is shown when URL is reached and console is showing MIME type errors.

error is:

Failed to load module script: The server responded with a non-JavaScript MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.

like image 728
HUSEN SHAIKH Avatar asked Jun 17 '19 13:06

HUSEN SHAIKH


1 Answers

One possible explanation for the error:
You get this behavior when you deploy your app into a subfolder, not directly on your base-URL. The HTML is found when you go to www.yourbase.com/yoursubfolder/index.html, but as the angular app fetches other resources from www.yourbase.com/resource.css instead of from www.yourbase.com/yoursubfolder/resource.css and your webserver probably serves some default page (maybe your www.yourbase.com/index.html) the content of your CSS becomes the content of that HTML page. That would explain the error.

To fix it build your angular app with:

ng build --prod --base-href yoursubfolder 
like image 86
andymel Avatar answered Sep 18 '22 08:09

andymel