Home » Nodejs » ECMAScript 6 modules in Node.JS

ECMAScript 6 modules in Node.JS

Posted by: admin November 29, 2017 Leave a comment

Questions:

Node.JS v0.11.3 claims to have support for ECMAScript 6 modules with the flag --harmony_modules.

I have tried various examples, such as the following.

module math {
    export var pi = 3.141593;
}

What is the syntax to get modules working in Node.JS?

Answers:

The modules implementation in V8 is incomplete. There’s parsing support when enabled with –harmony-modules, but support of the actual functionality was put on hold. The reason for this is because the specification for how ES6 modules will actually work has been in the works and is still not fully nailed down.

The implementation in Continuum (the linked screenshot from Crazy Train’s answer) dates back to an interim spec from November 2012 and is now woefully out of date because of the ongoing changes to the ES6 module’s spec. This is why the V8 devs put development of support for modules on hold.

It seems like the modules spec is approaching stability (though I expect we’ll see small refinements for a while) and I think (hope at least) that we’ll see SpiderMonkey and V8 moving forward with implementations over the next 6 months.

Useful links:

Questions:
Answers:

You can use Continuum, which is an ES6 virtual machine written in (current) JavaScript.

enter image description here