5

I'm building a project using WebStorm 2016.2.2. I use version 6.6.0 of Node.js. I have set the JavaScript version to ES6, but I get "unexpected token" errors for both import and export keywords. I don't get errors for Lambda expressions BTW.

Why do I get this error? Am I doing something wrong or Node just does not support import and export without Babel (even though I have set the JavaScript version to ES6)?

LazyOne
  • 158,824
  • 45
  • 388
  • 391
Alon
  • 10,381
  • 23
  • 88
  • 152
  • can you post an excerpt of the code, please? – mtsdev Oct 06 '16 at 16:34
  • `I get "unexpected token" errors for both "import" and "export" keywords` this sounds like ESLint complaining, not Node.js. You have to enable import/export separately, as enabling ES6 enables anything _but_ them. – VLAZ Oct 06 '16 at 16:35

2 Answers2

7

Node.js supports CommonJS modules, however support for ECMAScript modules is currently being designed.

In the meantime, you'll have to use Babel to transform ECMAScript modules to CommonJS. Try using a minimal preset for Node.js builds, like babel-preset-node6.

Filip Dupanović
  • 32,650
  • 13
  • 84
  • 114
4

es6 does support import and export, node 6 does not support es6 import/export up till now as far as I know.

This question can be helpful: NodeJS plans to support import/export es6 (es2015) modules

Community
  • 1
  • 1
Stavros Zavrakas
  • 3,045
  • 1
  • 17
  • 30