6

I've understood that I'm using react.js version 15.6.2. I know this because doing this in my code:

console.log(React.version);

results in this console output:

15.6.2

I want to upgrade to React@^v16.2.0. I tried doing this:

sudo npm cache clean -f
sudo npm install -g n
sudo n stable
sudo n latest

But nothing changes. I get the same version output in the console. How do I upgrade node?

EDIT:

Here's the situation, I'm in a project folder with the following hierarchy:

enter image description here

node_modules seems to contain the react installation, since it has a react folder with a package.json file containing the version number 15.6.2.

I've tried both npm update --save react and npm update -g react. None worked. Same thing happens, and the same version number can be found in node_modules/react/package.json. I even tried to run npm install again before hosting with npm start. Any other suggestions?

Sahand
  • 7,980
  • 23
  • 69
  • 137

1 Answers1

9

Use npm update --save react to update to latest version. For a specific version use npm update --save react@16.2.0.

React should not be installed globally but only for your project. If this is not the case use -g instead of --save

UPDATE

Okay my fault. Just use npm install --save react@16.2.0. This installs the new version.

Kruspe
  • 146
  • 8
  • --save is no longer needed. Correct me if i'm wrong. – Pistolpete . Apr 11 '18 at 11:49
  • @Kruspe, I tried your solution. Still doesn't work. I put the results in an edit. – Sahand Apr 11 '18 at 11:50
  • @Pistolpete. In NPM v5 and above, `-S`/`--save` is the default. In v4 and below, you have to specify it. So as long as their Node/NPM installation is up to date, you're correct. – Joe Clay Apr 11 '18 at 12:20
  • 1
    Okay i updated my answer. This worked for me. @Pistolpete. if react is already in your package.json --save is not needed otherwise --save adds the dependency to your package.json – Kruspe Apr 11 '18 at 12:20