【问题标题】:Import image from './image.jpeg' results Failed to load module script The server responded with a non-JavaScript MIME type of "image/jpegerrorImport image from './image.jpeg' results Failed to load module script 服务器以“image/jpegerror”的非 JavaScript MIME 类型响应
【发布时间】:2019-12-12 15:18:53
【问题描述】:

我正在尝试使用以下方法导入图像:

import image from 'image.jpeg';

弹出以下错误。

加载模块脚本失败:服务器以“image/jpeg”的非 JavaScript MIME 类型响应。根据 HTML 规范对模块脚本强制执行严格的 MIME 类型检查。

在我的index.html 中,我将主脚本文件导入为:

<script src="index.js" type="module"></script>

然后在index.js

import image from 'image.jpeg';

当我使用 Chrome 运行它时,会导致上述错误。有什么帮助吗?

【问题讨论】:

    标签: javascript html


    【解决方案1】:

    在网络浏览器中运行的 JavaScript只能导入 JavaScript 模块。

    有一些工具(例如 WebPack)可以导入图像,但您没有使用其中之一。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-09
      • 2019-11-08
      • 2020-05-09
      • 2021-01-26
      • 2020-12-04
      • 2020-10-13
      • 1970-01-01
      • 2018-05-04
      相关资源
      最近更新 更多