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

Shubham Verma
4 min readJan 23, 2020

--

How to resolve this issue “SyntaxError: Block-scoped declarations” and how you can change your node version?

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

Error “Block-scoped declarations not yet supported outside strict mode” comes while you want to do build your app.
It usually comes when you do “gulp serve” or `gulp — production”, It can come on your local or on your cloud environment like “Alpha, Beta or Production”.

I was facing this issue just some days before on the cloud only. After exploring all the things we were able to replicate on local.

How I replicate it on the local machine:

* Take out the pull from master ( Updated code ).
* Delete older “node_modules” directory from my local machine using the command “sudo rm -rf node_modules”
* run command “npm update”
* After successful “npm update” run command “npm install”
*
Run command “gulp serve” — here you can get the error if not then go to the next command
* Run command “gulp — production” => here you can get the errors below:

Getting errors while gulp — production

What is the actual problem :

This error comes because, in your app’s package.json, there are some dependencies that have issues with the current node version.
These issues you can see while running the command “sudo npm install” as below:

-\|-\|-|/-\/-\WARN engine atob@2.1.2: wanted: {"node":">= 4.5.0"} (current: {"node":"4.2.6","npm":"2.14.12"})

or

WARN engine webpack@2.7.0: wanted: {“node”:“>=4.3.0 <5.0.0 || >=5.10"} (current: {“node”:“4.2.6",“npm”:“2.14.12"})

or

WARN engine loader-runner@2.4.0: wanted: {"node":">=4.3.0 <5.0.0 || >=5.10"} (current: {"node":"4.2.6","npm":"2.14.12"})

It means, the dependencies ( in package.json) aren’t compatible with your current node version, So you need to upgrade the compatible node version.

How to resolve this issue:

We can not put many versions on nodejs according to every dependency, so we need to find the common working and compatible version of nodejs.
Maybe your app is using a very lower version of the node and you have a lot of node versions in the market.
Like my app was using version 4.2.6 of nodejs as:

Using 4.2.6, the older version of nodejs

And we have a lot of node version in the market:

Versions available in the market

So, here is a question, Which node version I should use?
For this, we need to explore the available versions and need to find out the best-fitted version for our app.
Let’s find out the best-fitted node version for this app:
our current version .: 4.2.6

Install nvm ( maybe already installed with npm/node ) and follow the below steps:

  1. Go with the greater node version ( >VERSION.* , Chosen VERSION= 5.0.0 )
  2. Delete older node-modules using the command “sudo rm -rf node_modules”
  3. Install the chosen node version using the command “nvm install VERSION ”
  4. Use that node version using command: “nvm use VERSION”
  5. Install the dependencies using the command: “sudo npm install”
  6. Do the build: “gulp serve”, If you are getting the same error again then repeat step 1.
  7. Do the production build: “gulp — production”
  8. If you are getting the same error again then repeat step 1.

……………………………………………………………………………

Example: First, I select the node version 5.2.0 then many more, and I was getting the same error, Now I decide to go with version 6.8.0 and it worked :)

  1. Select the version 6.8.0
  2. sudo rm -rf node_modules
  3. nvm install 6.8.0
  4. nvm use 6.8.0
  5. sudo npm install
  6. gulp serve
gulp serve

7. gulp — production

gulp production

Now I resolved this issue.

Changed the node version to 6.8.0

Now you have the idea of how you can get rid of this issue? and how you can change your node version of your app?.

If you are interested in Nodejs or javascript then the below link will help you a lot:
Every Nodejs Developer Should Read These Articles

Thanks for reading

--

--

Shubham Verma

A full-stack developer, In my free time, I write blogs and play guitar. I am both driven and self-motivated.