本文介绍了Angular-无法加载模块脚本:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在生产中有angular 8前端应用程序,并且其加载模块脚本失败:服务器以非JavaScript MIME类型"text/html"响应.根据HTML规范对模块脚本强制执行严格的MIME类型检查.

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

main-es2015.fcc7123d15fd9c113b00.js:1

vendor-es2015.d8d7d81cc2b06ece8c91.js:1

vendor-es2015.d8d7d81cc2b06ece8c91.js:1

我该如何解决??

推荐答案

我想与我在工作所在的组织中遇到的相同问题分享经验.

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

我有一个Angular 9应用程序,当我部署到Stage环境时,我的控制台出现了三个错误,显示为由于Mime类型而导致模块未加载".这在所有其他环境中都可以正常工作,经过大量的努力,发现该网站下的文件无法访问.例如.部署Angular应用程序时,将获得index.html文件和许多其他js文件.该网站存在权限问题.该网站托管在Rackspace中,并且FireWall尚未配置为可以访问网站正下方的文件.

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.

  • /资产*
  • /*.css
  • /*.js
  • /*.ico
  • /*.html

我对您的问题的唯一区别是您提到它有时会起作用.

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

还有另一篇帖子,请尝试基于基本引用来解决此问题,因为这些js文件不是已投放/已加载

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.

这篇关于Angular-无法加载模块脚本:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-18 17:52
查看更多