【问题标题】:Mime error with Angular 8 in Firebase HostingFirebase 托管中 Angular 8 的 Mime 错误
【发布时间】:2019-11-16 06:29:48
【问题描述】:

我有一个 Angular 8 应用程序,它托管在 Firebase 上,并在客户端运行:Go-Astilectron(Astilectron 0.30 和 Electron 4.0.1)。

问题是我的一些客户端出现以下错误(它发生在加载 Angular 代码时,所以 Astilectron 只显示一个空白页面):

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.
main-es2015.5a90aaf45a8347384655.js:1 

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.

在某些情况下,我们仅通过重新加载页面即可解决此问题,但在其他情况下,无论我做什么,页面都无法加载。

我做了一些研究,发现这可能与注册服务工作者的应用程序有关,但这不是我的情况。

另外,由于我使用 Firebase 托管服务于一个静态站点,因此我没有进行任何 MIME 配置。

谁能帮帮我?

【问题讨论】:

    标签: angular firebase electron firebase-hosting


    【解决方案1】:

    确保index.html 中的head 包括:

    <base href="/">
    

    见:https://github.com/angular/angular-cli/issues/10325#issuecomment-399329033

    在注册表 mime 类型设置不正确的 Windows 机器上运行 Python 服务器时也会发生此错误。

    见:https://github.com/pallets/flask/issues/1045#issuecomment-42202749

    【讨论】:

    • 您好,感谢您的回答!我的 index.html 确实有 &lt;base href="/"&gt;。我会检查受影响机器的注册表
    • 您好,我已经检查过,这台计算机的注册表似乎没有问题。我没有找到任何带有 text/plain 的条目。
    • 您好,刚刚添加了这部分,问题就在于此。有趣的是,我的 dev 分支运行良好,而我的 prod 分支无故中断。
    • @Felipe 您好,您找到解决此问题的方法了吗?
    • 嘿@TerryWindwalker,是的。如果我没记错的话,问题出在 Windows 注册表中,根据此链接:github.com/pallets/flask/issues/1045#issuecomment-42202749 Cristopher 共享。
    【解决方案2】:

    我遇到了这个问题。

    转到 angular.js 并检查“outputPath”的值。如果它设置为“dist/your-project-name”之类的内容,请尝试将其更改为“dist/”,重新部署,然后对您的站点进行硬刷新 (Ctrl+F5)。

    【讨论】:

      【解决方案3】:

      我通过简单地运行 npm cache clear -f 然后刷新浏览器解决了这个问题。

      希望这会有所帮助!

      【讨论】:

        【解决方案4】:

        对我来说,浏览器的清空缓存和硬重载已经解决了这个问题。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-04-20
          • 2019-01-22
          • 1970-01-01
          • 2020-06-04
          • 2016-09-18
          • 1970-01-01
          相关资源
          最近更新 更多