0

I tried to install node.js by NVM in Ubuntu 16.04 server by following this link. And I got:

root@instance-15s8fbzx:/opt# nodejs --version
v4.2.6
root@instance-15s8fbzx:/opt# npm --version
5.3.0
root@instance-15s8fbzx:/opt# node --version
v8.4.0

Then, we I run a mean-stack project by sudo npm start, I got

class User {
^^^^^

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

Then, I saw this link, I think maybe because the nodejs version is not correct. I have another server with v5.12.0 as the version of nodejs, and the project worked well there.

Then, I tried to do

sudo npm install -g npm
sudo npm install -g n
sudo n stable
sudo ln -sf /usr/local/n/versions/node/8.4.0/bin/node /usr/bin/node

But the version of the nodejs is still 4.2.6. Does anyone know how to upgrade its version to 5.12.0?

SoftTimur
  • 5,630
  • 38
  • 140
  • 292
  • I think `nodejs` is the name used for the node binary in some Linux distributions. Both nvm and n install a binary named node. So you can ignore nodejs, or uninstall it using your distribution package manager. – shadowspawn Feb 08 '22 at 01:09
  • For some info on the reason for the naming and how to use the Ubuntu package to get a binary called node: https://stackoverflow.com/questions/18130164/nodejs-vs-node-on-ubuntu-12-04 – shadowspawn Feb 08 '22 at 06:28

2 Answers2

0

After you have installed NVM and you have installed the necessary version of node, you select the node version as follows:

> nvm use v5.12.0
Daniel Flippance
  • 7,734
  • 5
  • 42
  • 55
0
After upgrading to the Nodejs version, the following error occurred for the Laravel and VUE js packages I already had: 

PHP Fatal error: During inheritance of IteratorAggregate: Uncaught ErrorException: Return type of Symfony\Component\HttpFoundation\ParameterBag::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in C:\xampp\htdocs\clerk\vendor\symfony\http-foundation\ParameterBag.php:210

To solve the issue, I did the following: 
  1. composer update
  2. npm update
  3. npm run dev
  4. php artisan serve
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 07 '22 at 18:45