Skip to content
Advertisement

Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of “text/html”

I deployed my angular application(Static webpage) on kubernetes and tried launching it from Google Chrome. I see app is loading, however there is nothing displayed on the browser. Upon checking on browser console , I could see this error

“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.” for (main.js,poylfill.js,runtime.js) files . I research few forums and one possible rootcause could because of type attribute in <script> tag should be type=text/javascript instead of type=module in my index.html file that is produced under dist folder after executing ng build. I don’t how to make that change as to these tags as generated during the build process, and my ng-build command is taken care by a docker command.

URL i’m trying to access will be something like : “http://xxxx:portnum/issuertcoetools

note: The host xxxx:portnum will be used by many other apps as well.

Are there any work-arounds or solutions to this issue?

index.html – produced after running ng-build in local, (which is the same i see in kubernetes POD too)

JavaScript

nginx.conf file

JavaScript

Advertisement

Answer

This error usually happens because you deployment was into a subfolder, so it seems like Angular is fetching you app directly from your base URL, so your html is found when you go to your domain.com/mysubfolder/index.html, but as the Angular fetches your resources from domain.com/index.html instead of domain.com/mysubfolder/index.html; I’m pretty sure this is the cause of your issue. You can resolve it building your app with:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement