Node: Destructuring Assignment doesn't work in node v 4.1.0 for me

Created on 28 Sep 2015  路  11Comments  路  Source: nodejs/node

This code:

function ololo() {
    return ['olo', 1337];
}

var [that, anotherOne] = ololo();

produces:

var [that, anotherOne] = ololo();
    ^

SyntaxError: Unexpected token [
    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
V8 Engine question

Most helpful comment

@dman777 that version of v8 will not ship with node 4.x. At least that version will ship in node v6.x.

All 11 comments

ES6 destructuring is not shipped yet in the V8 version that we have in node v4.
However you can make your sample work if you run node with the flag --harmony-destructuring. Be aware that this feature may have bugs or be incomplete (this is why it's behind a flag).

Ok, thanks. When do you plan to ship full support of ES6 in node(if it is not a secret)?

@andrew-medvedev Most of the information you'd want about ES6 and Node can be found at https://nodejs.org/en/docs/es6/. In a nutshell, ES6 features aren't in Node core. They're in v8, the underlying JavaScript engine used by Chrome, Opera, and Node.js. So Node won't ship with a feature before v8 ships with it. Here's the v8 issue for the destructuring feature: https://code.google.com/p/v8/issues/detail?id=811

@Trott Ty, it's now clear for me

v8 shipped with this yesterday (bug closed 11 hours ago and now present in the canary build of chrome). What's the lead time on a node release using this version of v8?

@leonaves According to chromestatus, this is fixed in v8 4.9.

According to the v8 4.9.x changelog, it's shipped by default in 4.9.295.

Node.js branch vee-eight-4.9 has V8 4.9.385.18.

You could help test that branch =). Does it work with your code?

One way to find out I suppose...

I would like this very much. However, I do not want to compile node manually or use the nightly branch. How long until V8 4.9.385.18 is shipped with the stable node 4.*?

@dman777 that version of v8 will not ship with node 4.x. At least that version will ship in node v6.x.

i have got error in node-wit node-module
/app/node_modules/node-wit/lib/wit.js:18
const {
SyntaxError: Unexpected token {

also i run following command
node --harmony_destructuring /home/bridgeit/Documents/fundu-hr-backend/node_modules/node-wit

but give error "node: bad option: --harmony_destructuring" and i using node version 6.2.2 ,npm version 3.9.5 and node -p process.version.v8 is 5.0.71.52

with Node version 6.6.0 (not npm) works perfect for me without any flag.

Was this page helpful?
0 / 5 - 0 ratings