msg.js:1 Uncaught SyntaxError: Cannot use import statement outside a module (at msg.js:1:1)
时间: 2023-08-14 08:15:10 浏览: 124
这个报错是因为在非ES模块中使用了import语句,而import语句只能在ES模块中使用。为了解决这个问题,你需要在script标签上添加module属性,如下所示:
```html
<script src="./index.js" type="module"></script>
```
这样浏览器就会将该脚本文件作为ES模块来解析。另外,确保你的index.js文件中也使用了正确的ES模块语法。
#### 引用[.reference_title]
- *1* [vue 新手提高和面试讲解](https://blog.csdn.net/Eternity_matt/article/details/118223644)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* *3* [Uncaught SyntaxError Cannot use import statement outside a module的解决方法](https://blog.csdn.net/Ajekseg/article/details/123431598)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文