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)); } 
8
  • 2
    iirc google chrome does not support modules yet. Commented Feb 19, 2016 at 3:06
  • Yeah, I noticed that... That's why my question is: Any information if they will support it before the final release ? Commented Feb 19, 2016 at 4:18
  • See this. Commented Feb 19, 2016 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. Commented Feb 21, 2016 at 16:54
  • Possible duplicate of ECMA 6 Not working although experimental js is enabled Commented Feb 21, 2016 at 17:11

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

2 Comments

How do you go about setting "Experiment Web Platform" features as enabled?
In the Chrome browser, type in the web address chrome://flags/. This action results in a list of experimental browser features available to you.
6

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

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

https://webkit.org/status/

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.