ES2015“进口”不能在节点v6.0.0中使用--harmony_modules选项 [英] ES2015 "import" not working in node v6.0.0 with with --harmony_modules option

查看:133
本文介绍了ES2015“进口”不能在节点v6.0.0中使用--harmony_modules选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用节点v6.0.0,并希望使用ES2016(ES6)。但是我意识到导入语法不起作用。在ES2015中编写模块代码不是导入的基础吗?我尝试使用 - harmony_modules 选项运行节点,但仍然有与import相同的错误。这是代码。

I am using node v6.0.0 and wanted to use ES2016 (ES6). However I realized that the "import" syntax is not working. Isn't "import" fundamental to for writing modular code in ES2015? I tried running node with --harmony_modules option as well but still got the same error about "import". Here's the code.

没有导入的工作代码:

'use strict';
let sum = 0;
class Number {

  addNumber(num1, num2) {
    return num1 + num2;
  }
}
let numberObj = new Number();
sum = numberObj.addNumber(1,2);
console.log("sum of two number 1 and 2 "+ sum);

使用import编写代码:

Notworking code with "import":

server.js

server.js

'use strict';
import Number from "./Number";

let sum = 0;


let numberObj = new Number();

sum = numberObj.addNumber(1,2);
console.log("sum of two number 1 and 2 "+ sum);

Number.js

Number.js

'use strict';
export default class Number {

  addNumber(num1, num2) {
    return num1 + num2;
  }
}

我还检查了http://node.green/ 查看受支持的es6,但无法理解为什么它不能与--harmony_modules选项一起使用。请帮助。

I also checked http://node.green/ to see the supported es6 however not able to understand why it doesn't work with --harmony_modules option. Please help.

推荐答案

他们还没有实现。

节点6.0.0使用V8版本,大部分ES6功能完成。不幸的是,模块不是其中一个完成的功能。

Node 6.0.0 uses a version of V8 with most of ES6 features completed. Unfortunately modules isn't one of those completed features.

node --v8-options | grep harmony 

正在进行和谐标志未完全实现,通常不会工作:

in progress harmony flags are not fully implemented and usually are not working:

- es_staging(启用测试和谐的功能(仅供内部使用))

- 和谐(启用所有完成的和声功能)

--harmony_shipping(启用所有发送的和声功能)

--harmony_object_observe(启用和谐Object.observe(正在进行))

- harmony_modules (启用和声模块(正在进行))

--harmony_function_sent (启用和谐功能(正在进行中))

--harmony_sharedarraybuffer(启用和谐共享缓冲区(正在进行)) >
--harmony_simd(启用和谐simd(正在进行中))

--harmony_do_expressions(启用和声do-expressions(正在进行中) ))

--harmony_i terator_close(启用和谐迭代器定稿(正在进行))

--harmony_tailcalls(启用和声尾呼叫(正在进行)) br>
--harmony_object_values_entries(启用和谐Object.values / Object.entries(正在进行))

--harmony_object_own_property_descriptors(启用和声Object.getOwnPropertyDescriptors ()(正在进行))

--harmony_regexp_property(启用和谐unicode正则表达式属性类(正在进行))

--harmony_function_name(启用和谐功能名称推断)

--harmony_regexp_lookbehind(启用和谐regexp lookbehind)

--harmony_species(启用和声Symbol.species )

--harmony_instanceof(启用和声支持实例)

--harmony_default_parameters(启用和谐默认参数)

--harmony_destructuring_assignment(启用和谐解构分配)

--harmony_destructuring_bind(启用和谐破坏绑定)

--harmony_tostring(启用和谐toString)

--harmony_regexps(启用和谐正则表达式扩展)

--harmony_unicode_regexps(启用和谐unicode regexps)

--harmony_sloppy(启用和谐功能在马虎模式)

--harmony_sloppy_let(启用和谐让步的​​模式)

--harmony_sloppy_function(启用和谐马虎功能块范围)

--harmony_proxies(启用和谐代理)

--harmony_reflect(启用和声反映API)

--harmony_regexp_subclass(启用和谐regexp子类)

--es_staging (enable test-worthy harmony features (for internal use only))
--harmony (enable all completed harmony features)
--harmony_shipping (enable all shipped harmony features)
--harmony_object_observe (enable "harmony Object.observe" (in progress))
--harmony_modules (enable "harmony modules" (in progress))
--harmony_function_sent (enable "harmony function.sent" (in progress))
--harmony_sharedarraybuffer (enable "harmony sharedarraybuffer" (in progress))
--harmony_simd (enable "harmony simd" (in progress))
--harmony_do_expressions (enable "harmony do-expressions" (in progress))
--harmony_iterator_close (enable "harmony iterator finalization" (in progress))
--harmony_tailcalls (enable "harmony tail calls" (in progress))
--harmony_object_values_entries (enable "harmony Object.values / Object.entries" (in progress))
--harmony_object_own_property_descriptors (enable "harmony Object.getOwnPropertyDescriptors()" (in progress))
--harmony_regexp_property (enable "harmony unicode regexp property classes" (in progress))
--harmony_function_name (enable "harmony Function name inference")
--harmony_regexp_lookbehind (enable "harmony regexp lookbehind")
--harmony_species (enable "harmony Symbol.species")
--harmony_instanceof (enable "harmony instanceof support")
--harmony_default_parameters (enable "harmony default parameters")
--harmony_destructuring_assignment (enable "harmony destructuring assignment")
--harmony_destructuring_bind (enable "harmony destructuring bind")
--harmony_tostring (enable "harmony toString")
--harmony_regexps (enable "harmony regular expression extensions")
--harmony_unicode_regexps (enable "harmony unicode regexps")
--harmony_sloppy (enable "harmony features in sloppy mode")
--harmony_sloppy_let (enable "harmony let in sloppy mode")
--harmony_sloppy_function (enable "harmony sloppy function block scoping")
--harmony_proxies (enable "harmony proxies")
--harmony_reflect (enable "harmony Reflect API")
--harmony_regexp_subclass (enable "harmony regexp subclassing")

这篇关于ES2015“进口”不能在节点v6.0.0中使用--harmony_modules选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆