14

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));
}
Ray Hulha
  • 10,701
  • 5
  • 53
  • 53
  • 2
    iirc google chrome does not support modules yet. – Nebula Feb 19 '16 at 03:06
  • Yeah, I noticed that... That's why my question is: Any information if they will support it before the final release ? – Ray Hulha Feb 19 '16 at 04:18
  • See [this](https://bugs.chromium.org/p/v8/issues/detail?id=1569). – Nebula Feb 19 '16 at 14:59
  • 1
    There is no "final release" of Chrome. There is just the next release, and then the one after that. Anyway, don't worry about native support in Chrome, just transpile your code like everyone else does. –  Feb 21 '16 at 16:54
  • Possible duplicate of [ECMA 6 Not working although experimental js is enabled](http://stackoverflow.com/questions/32809728/ecma-6-not-working-although-experimental-js-is-enabled) – Felix Kling Feb 21 '16 at 17:11
  • A question like this isn't a good fit for Stack Overflow. Imagine we would get questions like this for every version of Chrome. What good is this information after the version was released? Look at the appropriate development channels. – Felix Kling Feb 21 '16 at 17:12
  • Chrome is a compiler just like Java. Different versions support different features. I don't see the difference. – Ray Hulha Feb 22 '16 at 11:21
  • @FelixKling SO should implement version tags... – ycomp Jun 23 '17 at 17:54

2 Answers2

13

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

Ray Hulha
  • 10,701
  • 5
  • 53
  • 53
  • How do you go about setting "Experiment Web Platform" features as enabled? – monsto Dec 07 '17 at 21:51
  • In the Chrome browser, type in the web address chrome://flags/. This action results in a list of experimental browser features available to you. – Ray Hulha Dec 08 '17 at 08:50
6

Safari Tech Review 19, via WebKit, now supports modules.

https://twitter.com/Constellation/status/806660783312543744

https://webkit.org/status/

backspaces
  • 3,802
  • 6
  • 34
  • 58