在文件 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/