dependency-time-machine: Update npm Packages in Order

Automatically update your package.json dependencies one by one in chronological order, ensuring compatibility and reducing errors

This article is outdated

The tools or APIs discussed here have changed significantly since this was written. The article is preserved for reference, but the code examples may no longer work as shown.

Updating Node dependencies is a headache. Things often break, or dependencies conflict because they’ve been updated at different times. It’s frustrating when you run into issues after an update, especially when you don’t know which package caused the problem.

Managing dependencies manually is time-consuming, and figuring out the right order to update them in is tricky. One outdated dependency can throw off your entire project, and fixing it can feel like you’re playing whack-a-mole with bugs.

I came across a handy package called dependency-time-machine (thanks pilotpirxie). It streamlines the process by updating your dependencies one at a time in the order they were released, making sure everything remains compatible and works together seamlessly.

How dependency-time-machine works

  • Reads your package.json
  • Finds the release dates for each dependency.
  • Updates them one by one, in the order they were released.
  • Runs your tests after each update to check for compatibility issues.

dependency-time-machine diagram

Usage

Run dependency-time-machine with npx to find the next recommended dependency to update.

Terminal window
$ npx dependency-time-machine --update --install
Need to install the following packages:
dependency-time-machine@1.3.4
Ok to proceed? (y) y
Fetching remote dependencies...
[1/8] apollo-server-hapi
[2/8] graphql
[3/8] hapi
[4/8] hapi-swagger
[5/8] inert
[6/8] mongoose
[7/8] nodemon
[8/8] vision
New version found: hapi@17.5.0 (2018-05-21T17:59:05.432Z)
Updating hapi@17.5.0 in /Users/trevorindreklasn/Projects/labs/graphql-nodejs-hapi-api/package.json...
Installing new version...
npm warn deprecated hapi@17.5.0: This version contains severe security issues and defects and should not be used! Please upgrade to the latest version of @hapi/hapi or consider a commercial license (https://github.com/hapijs/hapi/issues/4114)
Installed

dependency-time-machine finds that hapi has a new version (17.5.0) released on May 21, 2018. It updates hapi in the package.json, installs the new version, and issues a warning that this version has known security defects and should be updated to a more secure version.

Terminal window
$ npx dependency-time-machine --update --install
Fetching remote dependencies...
[1/8] apollo-server-hapi
[2/8] graphql
[3/8] hapi
[4/8] hapi-swagger
[5/8] inert
[6/8] mongoose
[7/8] nodemon
[8/8] vision
New version found: mongoose@5.1.2 (2018-05-21T20:19:18.763Z)
Updating mongoose@5.1.2 in /Users/trevorindreklasn/Projects/labs/graphql-nodejs-hapi-api/package.json...
Installing new version...
Installed

Skipping Major Versions

Use the --stop-if-higher-major-number flag to skip over major versions. This will prevent the tool from updating to the next major version and instead keep it within the current major version range, ensuring more stable updates. Here’s an example:

Terminal window
$ npx dependency-time-machine --update --install --stop-if-higher-major-number
Fetching remote dependencies...
[1/7] apollo-server-hapi
[2/7] graphql
[3/7] hapi
[4/7] hapi-swagger
[5/7] inert
[6/7] mongoose
[7/7] vision
New version found: mongoose@5.2.6 (2018-07-30T23:51:37.527Z)
Updating mongoose@5.2.6 in /Users/trevorindreklasn/Projects/labs/graphql-nodejs-hapi-api/package.json...
Installing new version...
npm warn deprecated inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
npm warn deprecated rimraf@2.6.3: Rimraf versions prior to v4 are no longer supported
npm warn deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported
npm warn deprecated circular-json@0.3.3: CircularJSON is in maintenance only, flatted is its successor.
Installed

In this case, we updated to mongoose@5.2.6, staying within the same major version (5.x.x), skipping any updates that would have moved to a higher major version (like 6.x.x or higher). This helps keep updates stable and avoids breaking changes from major version bumps.

Excluding Dependencies

To skip certain dependencies from being updated, use the -e flag:

Terminal window
$ npx dependency-time-machine --update --install -e hapi
Fetching remote dependencies...
[1/8] apollo-server-hapi
[2/8] graphql
[3/8] hapi (excluded)
[4/8] hapi-swagger
[5/8] inert
[6/8] mongoose
[7/8] nodemon
[8/8] vision
New version found: vision@5.3.3 (2018-06-08T13:26:01.447Z)
Updating vision@5.3.3 in /Users/trevorindreklasn/Projects/labs/graphql-nodejs-hapi-api/package.json...
Installing new version...
npm warn deprecated vision@5.3.3: This version has been deprecated in accordance with the hapi support policy (hapi.im/support). Please upgrade to the latest version to get the best features, bug fixes, and security patches. If you are unable to upgrade at this time, paid support is available for older versions (hapi.im/commercial).
Installed

Hapi was excluded from the update process:

Terminal window
[3/8] hapi (excluded)

What about private registries? Not a problem.

Use the -r flag to specify your own private registry URL. Replace the example URL with your own.

Terminal window
$ npx dependency-time-machine --timeline -r https://npm.mycompany.com
Fetching remote dependencies...
[1/8] apollo-server-hapi
Error fetching data https://npm.mycompany.com/apollo-server-hapi
Error: getaddrinfo ENOTFOUND npm.mycompany.com
at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:120:26) {
errno: -3008,
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'npm.mycompany.com'
}

Sources


Trevor I. Lasn

Trevor I. Lasn

Tech executive with over a decade of experience programming and building products. Building 0xinsider.com, ceodumps.com and whiteheap.com.



Related Articles

Check out these related articles that might be useful for you. They cover similar topics and provide additional insights.

Developer tools
20 min read

residue-cli removes a Git worktree only when nothing in it would be lost. How its 15 checks decide, how it deletes and restores, and residue-ui for the Mac.

Nov 9, 2026
Read article
Developer tools
13 min read

List of useful Unix terminal commands to boost your productivity. Here are some of my favorites.

Aug 21, 2024
Read article
Developer tools
6 min read

Repomix, formerly Repopack, packs a whole code repository into one file you can share with Claude or ChatGPT. Usage, key features and a word of caution.

Oct 21, 2024
Read article
Developer tools
5 min read

Pkl, pronounced pickle, is Apple's open source configuration-as-code language, with schemas, validation and immutable values. How it compares to JSON and YAML.

Nov 1, 2024
Read article
Node.js
7 min read

Express 5.0 shipped on October 15, 2024, and 5.1.0 is now the npm default. Removed methods, new path matching, async error handling and Node.js 18+.

Sep 16, 2024
Read article
Node.js
5 min read

Sharp resizes, rotates and converts images in Node.js. It reads JPEG, PNG, WebP, GIF and SVG and writes WebP, AVIF and more. Code for each common task.

Oct 28, 2020
Read article
Developer tools
5 min read

Mermaid.js is a simple markdown-like script language for generating charts from text via JavaScript

Oct 30, 2019
Read article
React
7 min read

Run a React app in Docker: write a Dockerfile, start it with Docker Compose, serve the production build with Nginx and deploy it to a VPS.

Jul 16, 2020
Read article
Developer tools
5 min read

eslint-plugin-depend flags npm packages like is-odd that plain JavaScript replaces. How to install and configure it, and its move to @e18e/eslint-plugin.

Aug 13, 2024
Read article

This article was originally published on https://www.trevorlasn.com/blog/dependency-time-machine. It was written by a human and polished using grammar tools for clarity.