问题描述
我是 ES6 (ECMAScript 6)的新手,我想在浏览器中使用其模块系统.我读到Firefox和Chrome支持ES6,但是使用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
Uncaught SyntaxError: Unexpected token import
我有一个test.html文件
I have a test.html file
<html>
<script src="test.js"></script>
<body>
</body>
</html>
和一个test.js文件
and a test.js file
'use strict';
class Test {
static hello() {
console.log("hello world");
}
}
export Test;
为什么?
推荐答案
许多现代浏览器现在都支持ES6模块.只要您使用<script type="module" src="...">
导入脚本(包括应用程序的入口点),它就可以工作.
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
Take a look at caniuse.com for more details:https://caniuse.com/#feat=es6-module
这篇关于浏览器中的ES6模块:Uncaught SyntaxError:意外的令牌导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!