浏览器中的ES6:Uncaught SyntaxError:意外的令牌导入 [英] ES6 in the browser: Uncaught SyntaxError: Unexpected token import

查看:150
本文介绍了浏览器中的ES6:Uncaught SyntaxError:意外的令牌导入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 ES6 (ECMAScript 6)的新手,我想在浏览器中使用模块系统。我读过ES6受Firefox和Chrome支持,但我使用 export

I'm new to ES6 (ECMAScript 6), and I'd like to use its module system in the browser. I read ES6 is supported by Firefox and Chrome, but I'm getting the following error using export

<$我收到以下错误c $ c>未捕获的SyntaxError:意外的令牌导入

我有一个test.html文件

I have a test.html file

<html>
    <script src="test.js"></script>
<body>
</body>
</html>

和test.js文件

'use strict';

class Test {

    static hello() {
        console.log("hello world");
    } 
}

export Test;    

为什么?

推荐答案

此帖中之前接受的答案现已过时。许多现代浏览器现在支持ES6模块。只要您使用< script type =modulesrc =...> 导入脚本(包括应用程序的入口点),它就能正常工作。

The previously accepted answer in this post is now outdated. Many modern browsers now support ES6 modules. As long as you import your scripts (including the entrypoint to your application) using <script type="module" src="..."> it will work.

查看 caniuse.com 了解更多详情:
https://caniuse.com/#feat=es6-module

这篇关于浏览器中的ES6:Uncaught SyntaxError:意外的令牌导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆