【问题标题】:Cannot load the script with the type "module"无法加载类型为“模块”的脚本
【发布时间】:2018-07-02 19:28:33
【问题描述】:

在文件script.js 中有ES6 的特征,如import。为此,我将script.js 连接为module,没有type = 'module' 浏览器会生成错误。但是当我连接脚本时

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

作为module,在Chrome browser (v67),控制台弹出错误:

在“文件:/// D:/PROJECT/playing_field/src/script.js”处访问脚本 CORS 策略已阻止 from origin 'null':无效响应。 因此不允许访问 Origin 'null'。

如何将脚本连接为模块?

【问题讨论】:

  • 使用网络服务器?

标签: javascript ecmascript-6 es6-modules


【解决方案1】:

您需要使用 Web 服务器为您的页面提供服务。如果您还没有配置并且正在使用 Google Chrome,您可以使用Web Server for Chrome

【讨论】:

    猜你喜欢
    • 2022-11-15
    • 2020-01-11
    • 1970-01-01
    • 2020-04-22
    • 2014-01-19
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    • 2011-09-21
    相关资源
    最近更新 更多