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
I have a test.html file
<html>
<script src="test.js"></script>
<body>
</body>
</html>
and a test.js file
'use strict';
class Test {
static hello() {
console.log("hello world");
}
}
export Test;
Why?
<script type="module"></script>
make sure you add that otherwise you will get that error. I was banging my head on the wall continually doing<script>import ... </script>
knowingly that chrome is now said to support ES6 modules without flags, then I noticed that the type attribute was needed to specify to the browser that this is an ES6 module, without which you get that exact error.