Block-scoped declarations not yet supported outside strict mode

拜拜、爱过 提交于 2019-11-28 06:47:36

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 https://deb.nodesource.com/setup_7.x | sudo -E bash -
sudo apt-get install -y nodejs

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

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.

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 https://deb.nodesource.com/setup_11.x | sudo -E bash -
sudo apt-get install -y nodejs

Your node isn't updated.

remove your node version, download and install the latest version.

in project root run:

npm rebuild

And try again:

npm run production

PS.: If you don't want remove your node version, download the new and run with this.

I was also facing the same issue and I have tried to run these command and now it is working. But before that uninstall the nodejs first

sudo apt-get update

apt-cache policy nodejs

sudo apt install nodejs

I hope your problem will be solved.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!