19

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
  • 1,067
  • 1
  • 8
  • 23

14 Answers14

28

This worked for me

npm cache clean -f 
sudo npm install -g n
sudo n latest 
Sakshi Mahajan
  • 449
  • 4
  • 11
7

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

Piros_K
  • 73
  • 6
4

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

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
1

You can uninstall create-react-app and reinstall a working version that supports the current node version like below to achieve this. Refer this answer for more info.

npm uninstall -g create-react-app
npm install -g create-react-app@3.4.1
create-react-app my-app --scripts-version 3.1.1
Tharusha
  • 635
  • 8
  • 25
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

Mbote-Joseph
  • 73
  • 1
  • 4
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
0

I think you have to choose YARN, Because NPM installs packages sequentially, Yarn performs parallel installation resulting in better speed and performance.

  1. First of all install yarn
  sudo apt remove yarn
  curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - 
  echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
  sudo apt-get update
    sudo apt-get install yarn -y
  1. Then
yarn create react-app project-name
0

Using WSL-1, node installed via nvm and this worked for me at least.

sudo apt-get remove-y nodejs
rm -rf ~/.nvm

sudo apt-get install nvm
nvm install --lts
nvm use --delete-prefix v18 
Hobnob
  • 61
  • 2
  • 7
0

I have been searching posts for hours.

I had the following when trying to use create-react-app:

sudo npx create-react-app frontend

create-react-app@5.0.1
Ok to proceed? (y) y
npm WARN deprecated tar@2.2.2: This version of tar is no longer supported, and will not receive security updates. Please upgrade asap.
You are running Node 12.12.0.
Create React App requires Node 14 or higher. 
Please update your version of Node.You are running Node 12.12.0.
    Create React App requires Node 14 or higher. 
    Please update your version of Node

However, my node and npm were up to date:

node -v
v19.4.0

npm -v
9.2.0

Even figured out how to check whether that version was installed:

nvm uninstall 12.12.0
N/A version is not installed...

I tried:

  • Cache clearing npm and npx.
  • pruning all old versions with "sudo n prune"
  • Deleting the npx cache directly, "sudo rm -rf ~/.npm/_npx", as some in related posts have suggested.
  • All other combinations of uninstalling/reinstalling packages listed on this thread.

It turns out the warning was really not a warning, and updating the tar worked:

sudo npm i tar 

I thought this should be added, since I haven't seen anything in the last few hours of searching that mentioned this.

0

I did every thing and followed every answer written here but none was able to solve the problem for me.

I later find a solution to the problem. I discover that i have the latest version installed but the active version is a lower version, which was installed in a different location from the current version.

How i solve it is by using NVM to select the version i want to use in vscode during development.

  1. install NVM using: curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
  2. Check if it is installed by using: command -v nvm
  3. if it is install by outputting nvm after you run the above command, then install the specific version of node you want to use using nvm: nvm install 14.7.0 or 16.3.0, 12.22.1, etc
  4. run this command to start using the version you just installed: nvm use node
  5. you can check which version you are currently using, by running this command: nvm which 14.7.0 or 16.3.0, 12.22.1, etc

wolla problem solved.

screen of the installed version and the active version

0

Uninstall the existing node on windows and install the latest node again Download Node.

OBrien Evance
  • 704
  • 5
  • 18
  • 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 May 27 '23 at 12:45
0

This is the guide for Linux users.

  1. Clear the npm cache to free up space.

    npm cache clean -f

  2. Install the n package globally using npm.

    npm install -g n

  3. Use the n package to switch the system's Node.js version to the latest stable release.

    sudo n stable