【发布时间】:2020-11-19 19:42:35
【问题描述】:
我在index.html 中实例化一个模块:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Hello Module</title>
</head>
<body>
<script type="module" src="./index.js"></script>
</body>
</html>
index.js 为空。
当我通过 py -3 -m http.server (Python 3.8.5) 提供此服务时,我收到 Chrome 错误:
Failed to load module script: The server responded with a non-JavaScript MIME type of "text/plain". Strict MIME type checking is enforced for module scripts per HTML spec.
我已阅读此错误的含义。我不知道如何配置 http.server 因为在此之前它对我来说是一个黑匣子。我是否已经过了 Python 的默认 (?) 服务器有用的点?
【问题讨论】:
-
请给我们看一下服务器代码。
-
请参阅 Python 问题跟踪器上的 issue35403 - 根据解决方案,您可能需要使用 Python 3.8。
-
@AKX 这就是我的困惑;我不知道 http.server 的代码在哪里或是什么。
-
不,请出示您使用
http.server的代码。 -
@AKX 好的,我的问题现在更彻底了。
标签: javascript python server