简体   繁体   English

无法加载模块脚本 - 在 index.html 中导入类

[英]Failed to load module script - importing classes in index.html

I am trying to load these two classes and I get the below error:我正在尝试加载这两个类,但出现以下错误:

"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." “加载模块脚本失败:服务器以“text/html”的非 JavaScript MIME 类型响应。按照 HTML 规范对模块脚本强制执行严格的 MIME 类型检查。

<script type="module">
    import { A, B } from './js/dist/loader';
</script>

<body>
   <div ng-view></div>

   <script src="js/lib.js"></script>
   <script src="js/main.js"></script>
   <script src="js/build/app.js"></script>
</body>

From MDN: "To get modules to work correctly in a browser, you need to make sure that your server is serving them with a Content-Type header that contains a JavaScript MIME type such as text/javascript . If you don't, you'll get a strict MIME type checking error along the lines of "The server responded with a non-JavaScript MIME type" and the browser won't run your JavaScript."来自 MDN:“要让模块在浏览器中正常工作,您需要确保您的服务器使用 Content-Type header 为它们提供服务,其中包含 JavaScript MIME 类型,例如text/javascript 。如果您不这样做,您'将收到严格的 MIME 类型检查错误,类似于“服务器以非 JavaScript MIME 类型响应”,并且浏览器不会运行您的 JavaScript。

I would probably start by taking a look at the header your server is sending over when delivering the pages.我可能会先看看您的服务器在传递页面时发送的 header。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM