javascript - Flask:加载模块脚本失败:服务器以“text/html”的非 JavaScript MIME 类型响应
问题描述
- 服务器:Python/Flask
- 操作系统:Ubuntu 18.04
- 香草JS
<script
type="module"
src="{{ url_for('static', filename='js/app.js') }}"
></script
我在 html 的正文底部包含了这个脚本标签。由于某些原因,当我使用烧瓶运行在本地运行服务器时,我在浏览器控制台中出现以下错误消息:
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.
为什么加载错误的 MIME 类型。我什至不确定是否有更多相关的细节。我会尽我所能来填补空白。
解决方案
我找到了解决方案。在 Flask 中,如果你像这样导入文件
import SomeClass from './utils'
然后它将标头中的内容类型设置为“html/text”,它会出错。要修复此导入,如下所示:
import SomeClass from './utils.js'
它将正确设置内容类型标头
推荐阅读
- javascript - 固定标题表出现水平滚动问题
- python - 您可以使用 Pyinstaller 访问多张照片吗?
- python - 如何在几秒钟内有效地报告固定长度的滑动窗口
- javascript - 无法修改已提交 FireStore 的 WriteBatch
- c# - 节点的 XML 代码更改值 - 显示的代码如何正确?
- sql - 使用 UNION 合并和融合两个 SQL 查询的结果
- angular - Angular ng 探针:获取对用于注入器的令牌的引用
- chromecast - Chromecast CAF3 支持 TTML+PNG
- underscore.js - 下划线中 groupBy 的 lodash 等价物
- java - 服务器进入无限循环并给出 GOOGLE_APPLICATION_CREDENTIALS 异常