ES2015“导入”在带有 --harmony_modules 选项的节点 v6.0.0 中不起作用

2024-02-01

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

没有“导入”的工作代码:

'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);

不使用“导入”的代码:

服务器.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

'use strict';
export default class Number {

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

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


它们只是还没有实施。

Node 6.0.0 使用 V8 版本,完成了大部分 ES6 功能。不幸的是,模块并不是那些已完成的功能之一。

node --v8-options | grep harmony 

进行中和谐标志没有完全实现并且通常不起作用:

--es_staging(启用值得测试的和谐功能(仅限内部使用))
--harmony(启用所有已完成的和谐功能)
--harmony_shipping(启用所有已发布的和谐功能)
--harmony_object_observe(启用“harmony Object.observe”(进行中))
--harmony_modules(启用“和谐模块”(进行中))
--harmony_function_sent(启用“和谐功能.sent”(进行中))
--harmony_sharedarraybuffer(启用“和谐共享数组缓冲区”(进行中))
--harmony_simd(启用“和谐 simd”(进行中))
--harmony_do_expressions(启用“和谐 do 表达式”(进行中))
--harmony_iterator_close(启用“和谐迭代器终结”(进行中))
--harmony_tailcalls(启用“和谐尾调用”(进行中))
--harmony_object_values_entries(启用“和谐Object.values / Object.entries”(进行中))
--harmony_object_own_property_descriptors(启用“harmony Object.getOwnPropertyDescriptors()”(进行中))
--harmony_regexp_property(启用“harmony unicode regexp 属性类”(进行中))
--harmony_function_name(启用“harmony 函数名称推断”)
--harmony_regexp_lookbehind(启用“和谐正则表达式lookbehind”)
--harmony_species(启用“和谐符号.species”)
--harmony_instanceof(启用“和谐实例支持”)
--harmony_default_parameters(启用“和谐默认参数”)
--harmony_destructuring_assignment(启用“和谐解构分配”)
--harmony_destructuring_bind(启用“和谐解构绑定”)
--harmony_tostring(启用“和谐 toString”)
--harmony_regexps(启用“和谐正则表达式扩展”)
--harmony_unicode_regexps(启用“和谐 unicode 正则表达式”)
--harmony_sloppy(启用“草率模式下的和声功能”)
--harmony_sloppy_let(在草率模式下启用“harmony let”)
--harmony_sloppy_function(启用“和谐草率功能块范围”)
--harmony_proxies(启用“和谐代理”)
--harmony_reflect(启用“和谐反射 API”)
--harmony_regexp_subclass(启用“和谐正则表达式子类化”)

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ES2015“导入”在带有 --harmony_modules 选项的节点 v6.0.0 中不起作用 的相关文章

随机推荐