Uncaught SyntaxError: Unexpected token 'export
时间: 2023-09-26 20:10:58 浏览: 236
vue-cli 打包后提交到线上出现 “Uncaught SyntaxError:Unexpected token” 报错
5星 · 资源好评率100%
Uncaught SyntaxError: Unexpected token 'export'错误通常出现在Vue项目中,当在index.html中引入一个结构如下的js文件时:
```javascript
const fn = (() => {
console.log("jinlaile");
})();
export default fn;
```
这个错误是因为这段代码使用了ES6的模块导出语法`export default`,而浏览器默认不支持ES6模块导出。解决这个问题的方法是在index.html文件的`<script>`标签中添加`type="module"`属性,像下面这样:
```html
<script src="static.js" type="module"></script>
```
这样可以告诉浏览器该脚本是一个ES6模块,从而正确解析`export default`语法。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [Vue项目报错:Uncaught SyntaxError: Unexpected token <](https://download.csdn.net/download/weixin_38593823/12949934)[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^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [Uncaught SyntaxError: Unexpected token ‘export](https://blog.csdn.net/u013558749/article/details/129672621)[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^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [Uncaught SyntaxError: Unexpected token ‘export‘ 解决方法](https://blog.csdn.net/Maxueyingying/article/details/128948087)[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^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文