flask 使用es6语法中 type='module' 报错

报错如下:

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.

解决办法

在flask中添加代码:

import mimetypes
# 防止es6语法报错
mimetypes.add_type("application/javascript", ".js", True)

举例

文件结构(在同一个文件夹下)

更多推荐

Failed to load module script: The server responded with a non-JavaScript MIME ty