4

I have angular 8 front end application in production and its 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.

This issue is happening only in production build that too not always , able reproduce only sometimes.

main-es2015.fcc7123d15fd9c113b00.js:1

vendor-es2015.d8d7d81cc2b06ece8c91.js:1

How do i fix it.?

Vishwanath.M
  • 6,235
  • 11
  • 42
  • 56

2 Answers2

0

Are you using serviceWorker? If so you have to add inside angular.json "serviceWorker": true for the configuration that you are using.

Johnny Tmd
  • 11
  • 4
0

I would like to share my experience with the same issue I was facing in the organization where I'm working.

I had an Angular 9 application and when I deployed to Stage environment, I got three errors in my console which showed as "module not loaded due to Mime type". This was working fine in all other environment and after much struggle, it was found that the files under the website were not having access. E.g. When you deploy an Angular application, you will get index.html file and many other js files. The website had permission issues. The site was hosted in the Rackspace and the FireWall was not configured to have access to the files right under the website.

Once the below access was provided, the app started working.

  • /assets*
  • /*.css
  • /*.js
  • /*.ico
  • /*.html

The only difference I see with your problem is that you have mentioned it is working sometimes.

There is another post Blocked because of a disallowed MIME type (“text/html”) : Angular 8 deployed on tomcat 9.0.30 fails to serve the assets try the solution based on base reference as those js files are not served/loaded

I hope this might help someone.

Karthik
  • 426
  • 4
  • 7