1

Background

I have a very sinmple nodejs app that uses the Object Destructur Operator of ECMA6

"use strict";

function bananas(){
    return {
        type: "fruit",
        color: "yellow"
    };
}

function eat(){
    var {
        type,
        color
    } = bananas();

    return `I eat ${type} colored ${color}`;
}

console.log(eat());

Problem

When I click the run button of index.js (or when you go right-click index.js and then select "Run this file")

I get the following error:

Debugger listening on [::]:15454
/home/ubuntu/workspace/server/index.js:16
    var {
        ^

SyntaxError: Unexpected token {
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.runMain [as _onTimeout] (module.js:441:10)
    at Timer.listOnTimeout (timers.js:92:15)

However, if I type in the bash command line node index.js I get the expected output:

I eat fruit colored yellow

Furthermore, typing node -v outputs:

v7.8.0

Question

It is my strong believe that the run option is not picking up the correct version of node. How can I fix that?

Notes

To update node I used nvm install 7.

4

1 回答 1

1

回答

我对问题的识别是正确的。要修复它,需要运行以下命令:

nvm alias default 7

学分

感谢 Harutyun的回答。

于 2017-03-29T09:58:33.180 回答