Angular - Failed to load module script:

可紊 提交于 2020-06-13 06:20:07

问题


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.?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/57866861/angular-failed-to-load-module-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!