Block-scoped declarations not yet supported outside strict mode

I had the same problem coused by the old version of nodejs package on Ubuntu. I've just updated to 7.5 and it's working.

curl -sL | sudo -E bash -
sudo apt-get install -y nodejs

This is because you don't have the latest version of NodeJS on your machine. I'm on Ubuntu so if you're on any kind of Linux distro try this.

curl -sL | sudo -E bash -
sudo apt-get install -y nodejs

I had faced the same problem with one of my test script in NodeJS and i resolved my error by using ECMAScript 5's strict mode.

"use strict";

Added above line at the top of my script and it works well.

Strict mode makes several changes to normal JavaScript semantics:

  1. Eliminates some JavaScript silent errors by changing them to throw errors.

  2. Fixes mistakes that make it difficult for JavaScript engines to perform optimizations: strict mode code can sometimes be made to run faster than identical code that's not strict mode.

  3. Prohibits some syntax likely to be defined in future versions of ECMAScript.

Upgrading node package is the solution here. Adding altenative steps to upgrade node package as there is no need to download, install and manage node versions yourself. You can use a module called n to upgrade you node package in Mac/Ubuntu

sudo npm install -g n
sudo n stable

This will install latest stable node package. You can run

node --version

If you are still seeing old version it might be directory issues where new package is installed. I had to create a symlink to make it work-

sudo ln -s  /usr/local/n/versions/node/9.0.0/bin/node  /usr/local/bin/node