Upgrading React version and it's dependencies by reading package.json
Using npm
Latest version while still respecting the semver in your package.json: npm update <package-name>
.
So, if your package.json says "react": "^15.0.0"
and you run npm update react
your package.json will now say "react": "^15.6.2"
(the currently latest version of react 15).
But since you want to go from react 15 to react 16, that won't do.
Latest version regardless of your semver: npm install --save react@latest
.
If you want a specific version, you run npm install --save react@<version>
e.g. npm install --save [email protected]
.
https://docs.npmjs.com/cli/install
Using yarn
Latest version while still respecting the semver in your package.json: yarn upgrade react
.
Latest version regardless of your semver: yarn upgrade react@latest
.
https://yarnpkg.com/lang/en/docs/cli/upgrade/
if you want to update your react and react-dom version in your existing react step then run this command I hope You get the latest version of react and react-dom.
Thanks
npm install react@latest react-dom@latest
Yes, you can use Yarn or NPM to edit your package.json.
yarn upgrade [package | package@tag | package@version | @scope/]... [--ignore-engines] [--pattern]
Something like:
yarn upgrade react@^16.0.0
Then I'd see what warns or errors out and then run yarn upgrade [package]
. No need to edit the file manually. Can do everything from the CLI.
Or just run yarn upgrade
to update all packages to latest, probably a bad idea for a large project. APIs may change, things may break.
Alternatively, with NPM run npm outdated
to see what packages will be affected. Then
npm update
https://yarnpkg.com/lang/en/docs/cli/upgrade/
https://docs.npmjs.com/getting-started/updating-local-packages
I highly recommend using yarn upgrade-interactive to update React, or any Node project for that matter. It lists your packages, current version, the latest version, an indication of a Minor, Major, or Patch update compared to what you have, plus a link to the respective project.
You run it with yarn upgrade-interactive --latest
, check out release notes if you want, go down the list with your arrow keys, choose which packages you want to upgrade by selecting with the space bar, and hit Enter
to complete.
Npm-upgrade is ok but not as slick.