gpt4 book ai didi

javascript - 无法加载类型为 "module"的脚本

转载 作者:行者123 更新时间:2023-11-29 23:19:49 25 4
gpt4 key购买 nike

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

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

作为模块,在Chrome浏览器(v67)中,控制台弹出错误:

Access to Script at 'file: /// D: /PROJECT/playing_field/src/script.js' from origin 'null' has been blocked by CORS policy: Invalid response. Origin 'null' is therefore not allowed access.

如何将脚本连接为模块?

最佳答案

您需要使用 Web 服务器来提供您的页面。如果您尚未配置并且正在使用 Google Chrome,则可以使用 Web Server for Chrome .

关于javascript - 无法加载类型为 "module"的脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51142608/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com