0

I recently came back to Node.js after my brief exploration of front end, and have found that IO.js has merged back with Node.js. So I downloaded Node.js v4.4.2 and I wanted to mess around with ES6 modules, which I was doing before my aformentioned hiatus, I seem unable to use them.

I went to the Node.js website and found how to enable them (--harmony_modules), and using that flag, I still got the following error:

main.js:1
(function (exports, require, module, __filename, __dirname) { import * from "lib/Tile"
                                                              ^^^^^^

SyntaxError: Unexpected token import
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:414:25)
    at Object.Module._extensions..js (module.js:442:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:311:12)
    at Function.Module.runMain (module.js:467:10)
    at startup (node.js:136:18)
    at node.js:963:3

Am I doing something wrong here, or is there a bug in the Module Implementation? The involved files are posted below:

main.js:

import * from "lib/Tile"

console.log(Tile)

lib/Tile.js

export class Tile {
    constructor(data = {}) {
        this.data = data
    }
}
bren
  • 4,176
  • 3
  • 28
  • 43
  • [*As a rule of thumb, if a feature is behind a flag, you can expect it to be half-baked or downright broken.*](https://github.com/nodejs/node/issues/2760) – Bergi Nov 22 '15 at 22:27
  • ES6 modules are not supported yet. Have a look at the Node documentation to learn which features are supported: https://nodejs.org/en/docs/es6/ (I wonder were you saw the `--harmony_modules` option). – Felix Kling Nov 22 '15 at 22:27
  • @FelixKling I saw it via the `node --v8-options | grep "in progress"` command – bren Nov 22 '15 at 22:31

0 Answers0