由于 MIME 类型不允许,加载模块被阻止

Pet*_*ang 6 javascript firefox npm ecmascript-6

Loading module from \xe2\x80\x9chttp://localhost:3000/d3.js\xe2\x80\x9d was blocked because of a disallowed MIME type (\xe2\x80\x9c\xe2\x80\x9d)我在尝试导入 d3.js 库时遇到问题。项目使用npm,在Firefox中遇到了该错误。

\n\n

索引.html

\n\n
<!DOCTYPE html>\n<html lang="en">\n  <header>\n    <meta charset="utf-8" />\n    <title>D3</title>\n  </header>\n\n  <body>\n    <div id="svg"></div>\n    <script src="./index.js" type="module"></script>\n  </body>\n</html>\n
Run Code Online (Sandbox Code Playgroud)\n\n

索引.js

\n\n
import * as d3 from "./d3.js";\n
Run Code Online (Sandbox Code Playgroud)\n