LoginSignup
0
0

More than 5 years have passed since last update.

node.jsで分割代入 (Destructuring assignment)が使えない

Posted at

node.jsで分割代入を使用した時にエラーが発生

私の場合は以下のようなコードでエラーが発生しました。

const hoge = {fuga: {aho: 1}};
const { aho } = hoge.fuga; // ← エラー!!

原因

私の使用していたNodeのバージョンが古かったせいです。
使用していたバージョンは v5.11.1です。

以下のコマンドを打つと対応してない旨が確認できました。

node --v8-options | grep harmony

--harmony_destructuring (enable "harmony destructuring" (in progress))が表示の中に含まれています。

Nodeのリリース履歴確認してインストールしなおしても良かったんですが、めんどくさかったので適当にv7.0.0をインストールしてみたら使えるようになっていました。

以上です。

ちなみに・・・

以下のコメントを参照するに、バージョン6から使用できるみたいですね:relaxed:
https://github.com/nodejs/node/issues/6183#issuecomment-209669719

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0