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

When you are installing some package or compiling some code which is depending on “npm” , you may get an error as below,

SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:374:25)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Function.Module.runMain (module.js:442:10)
    at startup (node.js:136:18)
    at node.js:966:3

Solution

This error can be resolved by upgrading node.js version to latest version,

$ rm -rf /usr/local/lib/node_modules 
$ sudo apt-get install nodejs 
$ sudo apt-get install npm 
$ sudo npm install n -g 
$ sudo n latest 

you can also update npm version to latest.

$ sudo npm install npm@latest -g 

Reference : How to install specific / latest node.js version on Ubuntu and How to upgrade / install latest version of npm on Ubuntu

Leave a Comment