Trying ES6 imports with Chrome but it doesn't seem to work

Ray Hulha picture Ray Hulha · Feb 19, 2016 · Viewed 15.8k times · Source

I am contemplating moving from Dart to ES6 but Chrome doesn't seem to support the new import statement which is critical to me.

I used the (named export) code from this site: http://www.2ality.com/2014/09/es6-modules-final.html

I tried it even with

<module import="main"><module>

I get the error: "Unexpected token import"

Any information if they will support it before the final release ?

code:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8" />
    <title>ES6</title>
</head>
<body bgcolor="blue">
  <script type="module" src="main.js"></script>
</body>
</html>

main.js

import { square, diag } from 'lib';
console.log(square(11)); // 121
console.log(diag(4, 3)); // 5

lib.js:

export const sqrt = Math.sqrt;
export function square(x) {
    return x * x;
}
export function diag(x, y) {
    return sqrt(square(x) + square(y));
}

Answer

Ray Hulha picture Ray Hulha · Feb 21, 2016

It works now, finally in Chrome 60 with the Experimental Web Platform features enabled.

Here is a test:
https://github.com/paulirish/es-modules-todomvc

See here for status news:
https://www.chromestatus.com/features/5365692190687232