Logo

dev-resources.site

for different kinds of informations.

How to Keep Project Dependencies Up-To-Date

Published at
11/19/2022
Categories
dependencies
npm
versions
updates
Author
joshhortt
Categories
4 categories in total
dependencies
open
npm
open
versions
open
updates
open
Author
9 person written this
joshhortt
open
How to Keep Project Dependencies Up-To-Date

If you are looking for a quick way to update your project dependencies to the latest versions, you are in the right place.

Due to bug patches, new features, and other changes, dependencies may eventually become out-of-date.

It becomes increasingly difficult to stay current with these upgrades the more project dependencies you have.

Packages that are out of date might compromise security and degrade performance. Vulnerabilities are prevented with updated packages.

This implies that regular dependency updates and checks are crucial.

You will discover how to accomplish it in only three or five optional steps in this article!

How to Check for Oudated Dependencies

It's vital to know that dependency package updates, even if it's a major version, may bring about breaking changes to your project.

Of course, upgrading dependencies is a blunt instrument. As you indicated, if the project is empty and nothing can break, it's okay.

On the other hand, if you're working on a more advanced project, you probably want to make sure that your dependencies haven't undergone any breaking changes before you upgrade.

For a quick overview of the number of dependency updates you need to first use npm oudated.

1. Check for Oudated Dependencies

The first step is to go to your project's directory and run:

$ npm outdated
Enter fullscreen mode Exit fullscreen mode

Every installed dependency will be examined by this command, and the current version will be compared to the most recent version in the npm registry.

It prints out as a table detailing all of the new available versions.

npm oudated example

There are no additional packages that need to be downloaded because it is built within npm.

For Yarn specific solution, refer to this StackOverflow answer.

How to Update Project Dependencies

Let's imagine you wish to update some dependencies in a project that has a few out-of-date ones.

Or maybe you ...

Consider that you wish to revisit a project of yours that has a little bit fallen by the wayside.

Regardless of the situation, you could question yourself:

  • How should I update them?
  • Should I update them all at once or one at a time?
  • Which tools or commands should I employ?

The 'npm-check-updates' package, which brings your project dependencies up to date, is the solution.

You have two options for using the package: either install it globally or use npx.

2. Update the dependencies with NPX

The second step is to go to your project's directory and run:

$ npx npm-check-updates
Enter fullscreen mode Exit fullscreen mode

The above command displays all the outdated dependencies from your project.

npx npm-check-updates example

The image illustrates an example output. The output shows the current versions and the latest versions.

I'd suggest npm-check-updates for an additional sophisticated and adaptable upgrading experience.
This package offers some extra customization options in addition to all that npm obsolete and npm upgradesย can accomplish.
However, a package installation might be necessary.

Install the npm-check-updates package globally to get going:

3. Update the dependencies Globally

The third step (optional) is to go to your project's directory and run:

$ npm-check-updates -u
Enter fullscreen mode Exit fullscreen mode

The command doesn't automatically install the new versions. It just overwrites your package.json file with the latest versions.

npx npm-check-updates -u example

That means you have to install them yourself, which takes us to the fourth step and fifth steps.

How to Install New Dependency Versions

4. Install Package Globally

The fourth step (optional) is to go to your project's directory and run:

npm install -g npm-check-updates
Enter fullscreen mode Exit fullscreen mode

5. Install the new versions

The last step is to install the new versions by running:

$ npm install

// or

$ yarn install
Enter fullscreen mode Exit fullscreen mode

After this, you are done! The project will use the latest versions.

Conclusion

Consistently updating your dependencies will improve the efficiency and security of your apps.

Useful tools to check for packages that need a version upgrade are npm outdated and npm-check-updates.

I advise testing them both to determine which offers a better developer experience.

I'm hoping that these techniques will be useful as you update your project dependencies!

dependencies Article's
30 articles in total
Favicon
Forge Compatibility Reports for module management
Favicon
A Developerโ€™s Guide to Dependency Mapping
Favicon
The Essence of Task Dependencies in Project Management: Definition & Example
Favicon
Wednesday Links - Edition 2024-09-11
Favicon
You Are Not Saved By IaC
Favicon
The Simplest Way to Extract Your Requirements.txt in Python
Favicon
How I can get away with never installing npm packages globally
Favicon
๐Ÿ“š How to see what changed in Composer files
Favicon
Advanced Usage of Dependencies and Models in FastAPI
Favicon
CDK Dependency Strategies
Favicon
How to link a local npm dependency with pnpm
Favicon
It depends! Exploring my favourite Renovate features for dependency updates
Favicon
ERESOLVE unable to resolve dependency tree
Favicon
๐Ÿ“ฆ Upgrading Dependencies
Favicon
Python env: be careful with requirements
Favicon
The Better Npm Audit ๐Ÿชฑ
Favicon
Choosing dependencies using deps.dev
Favicon
Tips and tricks for using Renovate
Favicon
How to Keep Project Dependencies Up-To-Date
Favicon
Automatically keep project dependencies up to date with Renovate
Favicon
Another cheat sheet for Dependabot
Favicon
When Package Dependencies Become Problematic
Favicon
Automatically manage Python dependencies with requirements.txt
Favicon
Dockerize the Spring Boot Application.
Favicon
Dependency Injection Explained
Favicon
I broke production 3 times in 3 weeks - Part II
Favicon
5 + 1 tips to reduce the noise of Renovate Bot
Favicon
Lock your Android dependencies ๐Ÿ”
Favicon
Sorting a Dependency Graph in Go
Favicon
The Essential Guide to Dependency Graphs

Featured ones: