0

I believe node v4.4.7 supports ES6. However node refuses to compile my program:

user1-$ node -v
v4.4.7

user1-$ node index.js
event-service.js:85
      let sql = 'SELECT * FROM group_events where id = ?';
      ^^^

SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode

I want to avoid 'use strict'. Any other options?

JBallin
  • 8,481
  • 4
  • 46
  • 51
runtimeZero
  • 26,466
  • 27
  • 73
  • 126
  • Maybe this answer? http://stackoverflow.com/questions/9031888/any-way-to-force-strict-mode-in-node – mab Sep 23 '16 at 18:32
  • I don't want to place 'use strict' on top of every file. Are there any other options ? – runtimeZero Sep 23 '16 at 18:33
  • I believed node was running in strict mode by default in v4.x. Wierd. Try to run `node --use_strict index.js` – Orelsanpls Sep 23 '16 at 18:36
  • 1
    Why not switch to a newer node version? The current stable version has much better ES6 support. – generalhenry Sep 23 '16 at 18:39
  • @generalhenry under node downloads.. the version that pops up is v4.5.. I am not that far off – runtimeZero Sep 23 '16 at 18:44
  • node.js v6 is the latest node.js version with the most ES6 support. And, regardless you should be happy to run your code in strict mode as it will save you many accidental headaches. – jfriend00 Sep 23 '16 at 18:57
  • The latest node version is 6.6, it is not the long term support version, but it will become LTS on October 1st – ndonohoe Sep 23 '16 at 18:58
  • 1
    @GrégoryNEUT place your response as an answer so I can mark it so – runtimeZero Sep 23 '16 at 19:02
  • @generalhenry will I not have to use --use_strict option in node 6.6 ? – runtimeZero Sep 23 '16 at 19:56
  • Yes and no. In 6.6 you no longer need strict mode for let, but strict mode still applies it's usual set of changes to the runtime. If/when node switches to es2015 modules you would no longer need to use strict at all since they are always run in strict mode. – generalhenry Sep 27 '16 at 19:59

1 Answers1

2

run node --use_strict index.js to force it using strict mode

Orelsanpls
  • 22,456
  • 6
  • 42
  • 69