4

I was trying to create a react app, but got following

$ npx create-react-app react-demo
npx: installed 67 in 6.045s
You are running Node 10.19.0.
Create React App requires Node 14 or higher. 
Please update your version of Node.

In the solution, this answer asks to run npm i -g npm@latest which gives another error:

$ sudo npm i -g npm@latest
npm does not support Node.js v10.19.0
You should probably upgrade to a newer version of node as we
can't make any promises that npm will work with this version.
You can find the latest version at https://nodejs.org/
/usr/local/lib/node_modules/npm/lib/npm.js:32
  #unloaded = false
  ^

SyntaxError: Invalid or unexpected token
    at Module._compile (internal/modules/cjs/loader.js:723:23)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at module.exports (/usr/local/lib/node_modules/npm/lib/cli.js:22:15)
    at Object.<anonymous> (/usr/local/lib/node_modules/npm/bin/npm-cli.js:2:25)
    at Module._compile (internal/modules/cjs/loader.js:778:30)

Solution to this error asks to uninstall npm which gives same error:

$ sudo npm uninstall -g npm
npm does not support Node.js v10.19.0
You should probably upgrade to a newer version of node as we
can't make any promises that npm will work with this version.
You can find the latest version at https://nodejs.org/
/usr/local/lib/node_modules/npm/lib/npm.js:32
  #unloaded = false
  ^

SyntaxError: Invalid or unexpected token
    at Module._compile (internal/modules/cjs/loader.js:723:23)
    //..
    at Module._compile (internal/modules/cjs/loader.js:778:30)

Solution to above error asks to install helper utility n, which also gives same error:

$ sudo npm install -g n
npm does not support Node.js v10.19.0
You should probably upgrade to a newer version of node as we
can't make any promises that npm will work with this version.
You can find the latest version at https://nodejs.org/
/usr/local/lib/node_modules/npm/lib/npm.js:32
  #unloaded = false
  ^

SyntaxError: Invalid or unexpected token
    at Module._compile (internal/modules/cjs/loader.js:723:23)
    //..
    at Module._compile (internal/modules/cjs/loader.js:778:30)

I am super confused whats happening here. How do I fix this?

PS: am quite new to npm and node.

Rnj
  • 641
  • 1
  • 2
  • 13

7 Answers7

5

My solution was to update ubuntu using $ sudo apt update Then use $ sudo n stable to install the latest version of nodejs

what you need is node manager using npm install -g n to install before using $ sudo n stable

Paros_K
  • 53
  • 6
2
  • I also got the same issue try this out

    1. curl -sL https://deb.nodesource.com/setup_16.x -o nodesource_setup.sh
    2. Inspect the contents of the downloaded script with nano (or your preferred text editor): nano nodesource_setup.sh
    3. When you are satisfied that the script is safe to run, exit your editor, then run the script with sudo: sudo bash nodesource_setup.sh
    4. sudo apt install nodejs
    5. node -v
Surya
  • 21
  • 3
2

This worked for me

npm cache clean -f 
sudo npm install -g n
sudo n latest 
Sakshi Mahajan
  • 111
  • 1
  • 10
2

Hola a todos yo lo resolví siguiendo los siguientes pasos Abrir un terminar y escribir lo siguiente para actualizar el nvm

 curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
             

Luego cerrar el terminal y volver abrirlo para que se actualice

A continuación instalar node 16.x con:

nvm install 16

Listo

En ingles, traducido con google translator

Hello everyone, I solved it following the following steps Open a terminate and type the following to update the nvm

  curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
             

Then close the terminal and reopen it to update

Next install node 16.x with:

 nvm install 16

Ready

0

To create a react app using the command npx create-react-app my-app needs a higher version of node that the one currently installed in your machine. To solve this I used the node version manager(nvm). I run the commands:-

  1. sudo apt update
  2. curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
  3. nvm --version
  4. nvm ls
  5. nvm ls-remote
  6. nvm install [version.number]

Example you can type nvm install v16.13.1 You are good to go! Reference Material:- https://phoenixnap.com/kb/update-node-js-version

0
  1. Verify that your installed node version is equal to or greater than the version that the create-react-app installer is complaining about by running node -v
  2. If necessary, you can install the latest stable node version by running npm i -g 
(At the time of this posting the latest LTS Version is 16.13.2 which includes npm 8.1.2)
  3. In the parent folder where you want to create your React App, run npm init -y
  4. While still in the parent folder, create your React App by running: npx create-react-app yourAppName
  5. Navigate to your newly created React App by running cd yourAppName
  6. Lastly, run npm start and view your new React App in your default browser.

That's it, good luck!

Armor IT
  • 1
  • 1
0

I had a similar problem, and this method worked for me.

curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash -
sudo apt-get install -y nodejs

for more details check out this question https://askubuntu.com/questions/426750/how-can-i-update-my-nodejs-to-the-latest-version

VJ Ranga
  • 101
  • 3
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 06 '22 at 06:40