javascript - Cannot use import statement outside a module(Vanilla Javascript)
问题描述
when i tried to import a class from one js file to another i got this error
Uncaught SyntaxError: Cannot use import statement outside a module
when i added type="module" to my script tags i got this error
Access to script at 'file link' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
any help on how to fix the error ?
解决方案
这可以通过将 type="module" 添加到我的脚本标签并从在 localhost 上运行的 HTTP 服务器提供我的 Web 文件而不是直接打开 html 文件来解决
这些答案很有帮助:
推荐阅读
- android - Twitter嵌入不渲染反应本机渲染html
- opencv - Python - OpenCV - 从视频中的库中检测对象
- oracle - 检查周休息日而不是插入周休息其他存在但仅获得例外
- python - 与 curl 一起工作,请求失败;如何修复我的请求代码?
- javascript - Visual Studio 2019 中带有参考路径的 JavaScript IntelliSense 不再工作
- sybase - 如何解决在 Sybase 中配置 Replication 服务器时无法连接到 RSSD 服务器
- mysql - 从数据库中获取唯一记录并具有所有逗号分隔的 id
- amazon-s3 - 如何在不使用火花的情况下在 s3 中压缩镶木地板文件
- r - 将日期时间(POSIXct)强制为日期时出现时区问题
- apache-spark - 火花稀疏矩阵