在Chrome中尝试导入ES6,但似乎无法正常工作 [英] Trying ES6 imports with Chrome but it doesn't seem to work
问题描述
我正在考虑从Dart迁移到ES6,但是Chrome似乎不支持对我来说至关重要的新import语句.
I am contemplating moving from Dart to ES6 but Chrome doesn't seem to support the new import statement which is critical to me.
我使用了此网站的(命名为导出)代码: http://www.2ality.com/2014/09/es6-modules-final.html
I used the (named export) code from this site: http://www.2ality.com/2014/09/es6-modules-final.html
即使使用
<module import="main"><module>
我收到错误消息:意外导入令牌"
I get the error: "Unexpected token import"
是否有任何信息支持最终发行版本?
Any information if they will support it before the final release ?
代码:
<!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));
}
推荐答案
现在可以正常使用,最后在启用了实验性Web平台功能的Chrome 60中运行.
It works now, finally in Chrome 60 with the Experimental Web Platform features enabled.
这是一个测试:
https://github.com/paulirish/es-modules-todomvc
Here is a test:
https://github.com/paulirish/es-modules-todomvc
请参阅此处获取状态新闻:
https://www.chromestatus.com/features/5365692190687232
See here for status news:
https://www.chromestatus.com/features/5365692190687232
这篇关于在Chrome中尝试导入ES6,但似乎无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!