If I run the command :
npm install react
I would expect it to install react 17 because apparantly version 17 is the latest version.
However after I run the comment, I see this in my package.json file
"react": "^16.14.0",
Am I missing something?
CodePudding user response:
I think it installed it from your local npm, as for me your command installed 17.0.2.
For installing latest you should use:
npm install --save react@latest
CodePudding user response:
"react": "^16.14.0",
This answer assumes there was an existing react 16 installation in your project.
The first number is a major version, when you increase first version number (e.g. 16 to 17) you can expect breaking changes, so package manager like npm shouldn't upgrade the version like that automatically - else your app will break. See semantic versioning 2.
If you want to do that you will have to manually change the version:
npm install react@17.0.0 react-dom@17.0.0
But also refer to docs for possible breaking changes.
CodePudding user response:
The installed version normally locked in package-lock.json (or yarn.lock if you're using yarn).
Npm/yarn will try with the locked version to avoid issues when deploy your code on production environment and the version conflict stuffs.
To upgrade your react version to latest version, please use the command as @jare25's mention.
npm install --save react@latest