Node: import??

Created on 2 May 2016  路  11Comments  路  Source: nodejs/node

I'm a simple man:

# OS X 10.11
$ node -v
v6.0.0

$ node foobar.js
(function (exports, require, module, __filename, __dirname) { import {_} from 'lodash';
                                                              ^^^^^^
SyntaxError: Unexpected token import
...

Everyone is buzzing about how import works now and ES6 compatibility is over 93%. Am I doing it wrong?

question

Most helpful comment

@Mycroft1891 @sant123 import and the semantics of es6 modules are still not implemented in any browser, and the implementation is still being discussed by the standards bodies

You can read more about what we are planning in this document

keep in mind this is a living document and we are still figuring things out.

Node uses the V8 JavaScript engine to run JavaScript. Language features are implemented in V8. Before being implemented in V8 the language features are standardized by the TC39.

So, import has been standardized by the TC39, but has not yet been implemented in V8 (or other engines such as SpiderMonkey or Chakra). There is still some discussion about ways that the standard might change to simplify the interaction between import / require.

Hopefully this makes a bit more sense, please feel free to ask other questions

All 11 comments

ES6 modules fall into the missing 7%. It's still not clear how or even if Node will support these yet.

Node.js doesn't support ES6 modules. As far as I know, there's not even a browser that supports them. I think only Chromium has experimental support.

Node ES6 Module Proposal: https://github.com/nodejs/node-eps/blob/master/002-es6-modules.md
Brower Support: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import

Moreover, ES modules are not ready yet, ECMAScript 2015 defines only the syntax.

I'm going to close this. Feel free to continue any discussion though.

Hi, 驴will Node.js support this ES6 feature? Just asking :smile:

@sant123 I'm using node v6.3.0 and it doesn't work yet ^^

That sounds sad @Mycroft1891, the only way you can use it is in Typescript but it will be great if this is implemented in Node.js

@Mycroft1891 @sant123 import and the semantics of es6 modules are still not implemented in any browser, and the implementation is still being discussed by the standards bodies

You can read more about what we are planning in this document

keep in mind this is a living document and we are still figuring things out.

Node uses the V8 JavaScript engine to run JavaScript. Language features are implemented in V8. Before being implemented in V8 the language features are standardized by the TC39.

So, import has been standardized by the TC39, but has not yet been implemented in V8 (or other engines such as SpiderMonkey or Chakra). There is still some discussion about ways that the standard might change to simplify the interaction between import / require.

Hopefully this makes a bit more sense, please feel free to ask other questions

As I recall, the _syntax_ of ES6 modules _is_ in fact implemented in ChakraCore, it's just the loader that is missing there. Probably a bit of a pedantic distinction, but the issue is ultimately that the functionality of the loader is still undecided.

FYI Chrome now supports ES6 Modules. Take a look at https://developers.google.com/web/updates/2017/07/devtools-release-notes#modules

Node.js now has experimental support for ES module loading as well.

Was this page helpful?
0 / 5 - 0 ratings