1

I'm wanting to start using this ES6 on Node.js but I can't make it work. I'm adding the node test.js --harmony flag but I'm still getting bad syntax errors.

It doesn't even pass the first lines of code:

import env from 'node-env-file'
import api from '../src'

I'm getting this

(function (exports, require, module, __filename, __dirname) { import env from 'node-env-file'
                                                              ^^^^^^
SyntaxError: Unexpected token import

How can I make my Node.js work with this type of syntax.

c4b4d4
  • 964
  • 12
  • 32
  • 1
    At the moment, Modules aren't supported natively. You can find a summary of which features are included in which versions at [node.green](http://node.green). In the meantime, you can use tools like [Babel](https://babeljs.io/) to translate. – Jonathan Lonowski Jul 26 '16 at 06:00

1 Answers1

1

import keyword is not yet supported by any version of node because there is no JavaScript engine yet that natively supports ES6 modules.

You have to use somekind of ES6 to ES5 transpiler like Babel or stick to require.

Rafal Wiliński
  • 2,240
  • 1
  • 21
  • 26