Node: --harmony_modules isn't working?

Created on 9 Sep 2015  ยท  16Comments  ยท  Source: nodejs/node

Following the documentation given here https://nodejs.org/en/docs/es6/

Sample Code

import {partial} from 'lodash'
console.log(partial)

command

node --harmony_modules  Javascript.js
/Users/tushar.mathur/Documents/Projects/temp/Javascript.js:1
(function (exports, require, module, __filename, __dirname) { import {partial} from 'lodash'
                                                              ^^^^^^

SyntaxError: Unexpected token import
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:413:25)
    at Object.Module._extensions..js (module.js:452:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:475:10)
    at startup (node.js:117:18)
    at node.js:951:3
โžœ  temp

OS: Mac OS 10.10.4
Node: 4.0.0

V8 Engine

Most helpful comment

V8 now has support for modules! And implementation has started in chromium ๐ŸŽ‰๐Ÿ†๐ŸŽŠ https://bugs.chromium.org/p/chromium/issues/detail?id=594639#c9

All 16 comments

Same results here, also on OS X (also with strict mode).
However, I'm not sure it is expected to work - I'm still transforming with BabelJS.

I guess I tweeted too soon :'(

modules are still in 'in progress' in v8 - so I'd withdraw that tweet anyway!

$ node --v8-options | grep 'in progress' 

Well, I wanted to experiment with them without using a transpiler which I finally could (Or can't).

See this comment: https://code.google.com/p/v8/issues/detail?id=1569#c29

V8 developers are currently waiting WHATWG loader spec to mature before completing the ES2015 module support.

Closing. As others point out, ES6 modules are not implemented in V8 yet. As a rule of thumb, if a feature is behind a flag, you can expect it to be half-baked or downright broken.

I have problem with '--harmony' in command, and use AppJS module node --harmony ./app/app.js and after run then have error 'AppJS requires Node is run with the --harmony command line flag' pls help me for this error. I use xubuntu OS node v4.2.2.
have add '--harmony' or no then always show error message 'throw new Error ('AppJS requires Node is run with the --harmony command line flag'); ^
Error: AppJS requires Node is run with the --harmony command line flag
at Object. (/var/www/tutorial/app/node_modules/appjs/lib/index.js:2:9)
at Module._compile (module.js:435:26)
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 Module.require (module.js:366:17)
at require (module.js:385:17)
at Object. (/var/www/tutorial/app/app.js:3:11)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)'

And by now what? Is import implemented in node.js 6.0?

AFAIK, V8 still doesn't support import/export, and thus neither does node.js v6.

https://bugs.chromium.org/p/v8/issues/detail?id=1569

Mar 16, 2016

Remove --harmony-modules flag and let embedder decide when modules are used

Modules already have a separate entrypoint into the engine (at the moment,
this is v8::ScriptCompiler::CompileModule, though that will change to
something like ParseModule). This meant that requiring a commandline flag
simply added an extra complexity burden on embedders. By removing the v8
flag, this lets embedders use their own flagging mechanism (such as d8's
"--module", or Blink's RuntimeEnabledFeatures) to control whether
modules are to be used.

Also remove old modules tests that were being skipped (since they test
very old, pre-ES2015 modules syntax).

sad

Yeah, keep the ticket closed. Modules in JS will never be truly standardized, and if they will, the standard will be obsolete or deprecated the next day, by a new solution, "new standard". Sad.

As node 6.5.0 still throws up on import ..., I guess it's still not in V8? Any news on that?
http://node.green/ is a great resource, but is there module support shown in any way?

V8 now has support for modules! And implementation has started in chromium ๐ŸŽ‰๐Ÿ†๐ŸŽŠ https://bugs.chromium.org/p/chromium/issues/detail?id=594639#c9

Node 9.3.0 still not supported.

@avesus i believe modules are slated for node 10 (i don't know if they will be backported). however you can use them in nightly builds with --experimental-modules

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Brekmister picture Brekmister  ยท  3Comments

filipesilvaa picture filipesilvaa  ยท  3Comments

loretoparisi picture loretoparisi  ยท  3Comments

cong88 picture cong88  ยท  3Comments

Icemic picture Icemic  ยท  3Comments