2

How to upgrade packages in react application automatically using commands? I don't want to manually check every library in package.json and check its latest version. I want to upgrade my package.json at one shot.

Hirak JD
  • 181
  • 2
  • 7

2 Answers2

3
npm i -g npm-check-updates
ncu -u
npm install

Looks like npm-check-updatesis the only way to make this happen now.

kingpanda419
  • 121
  • 2
0

Upgrading libraries, frameworks in Javascript project is surely a tiresome and complex process. However, it has much more benefits in the long run and stability .

Here are the main reasons why upgrading libraries are important:

  •  New features: Most dependencies have a clear roadmap for new features.

  • ️ Performance improvements: In addition to new features, performance improvements are also made frequently.

  • Fixed bugs: Although it is normal to find bugs in libraries that you depend on, patch releases help fix these issues.

  •  Security patches: Security patches are one of the most important reasons to have your libraries up-to-date.

The manual process is too tiresome as you need to check for the latest version of each package. So make it easier we will be using two separate methods.

Using npm-check-updates

npm-check-updates upgrades your package.json dependencies to the latest versions, ignoring specified versions.

Please follow the steps below -

  • Install npm-check-updates

  • Run npm-check-updates to list what packages are out of date

  • Run npm-check-updates -u to update all the versions in your package.json

  • Run npm update as usual to install the new versions of your packages based on the updated package.json

If you do not want to install npm-check-updates in machine, you can follow the steps below-

  • run npx npm-check-updates (This will list down all the outdated packages in package.json)

  • Run ncu -u to upgrade package.json

  • npm install to install the packages

Check your project by running the application and verifying the up-gradation. There might be issues in your code that might as part of up-gradation. In such scenario please check the release notes of the package and make the due changes in code.

Hirak JD
  • 181
  • 2
  • 7