10

I already had node 0.10.* and I installed nvm, then through nvm I installed 0.11.13 and 0.10 again.

node --version gives back 0.11.13

I try to use some of the ES6 features I read about and nothing I tried works.

I run my script with node --harmony index.js

...args says SyntaxError: Unexpected token .

let x = 5; also gives an error - SyntaxError: Unexpected identifier

Where can I find what's currently supported in 0.11.13?

Madd0g
  • 3,841
  • 5
  • 37
  • 59
  • Are you missing strict mode by chance? http://stackoverflow.com/a/11326647/362536 – Brad Jul 16 '14 at 03:06
  • @Brad - I was missing that, oops. I added that to the top of the file and now I get a different error - SyntaxError: Unexpected strict mode reserved word in `let` – Madd0g Jul 16 '14 at 05:51

2 Answers2

8

Try this instead

"use strict"
let x = 5;
console.log(x)

It will work.

run it like following

node --harmony file.js
Mritunjay
  • 25,338
  • 7
  • 55
  • 68
  • 1
    I now get this after I added "use strict" to the top of the file. SyntaxError: Unexpected strict mode reserved word – Madd0g Jul 16 '14 at 05:46
  • 1
    @Madd0g this error occurs when you run command without `--harmony` flag. Run it with `node --harmony file.js` – Mritunjay Jul 16 '14 at 06:17
  • 4
    Wow. `node --harmony script.js` is not the same as `node script.js --harmony` – Madd0g Jul 16 '14 at 07:51
  • 2
    @Madd0g No, it definitely isn't. You should have put that in your question. What you were doing was passing arguments to your Node.js script, not to Node itself. – Brad Jul 16 '14 at 13:16
3

I had this same issue and found that I was somehow running node 0.12.7 (I know, right?!). Upgrading to the latest (5.6.0) resolved the issue.

Phil
  • 2,732
  • 19
  • 20