DEV Community

Sreekar Reddy
Sreekar Reddy

Posted on Originally published at sreekarreddy.com

๐Ÿงถ Dependency Hell Explained Like You're 5

When your packages disagree about versions

Day 155 of 155

๐Ÿ‘‰ Full deep-dive with code examples


The Recipe Chain Analogy

You install one package. It quietly brings its own shopping list, and every item on that list brings another.

you            -> chart-library ^2.0.0
you            -> form-library  ^3.0.0
chart-library  -> color-utils   ^1.0.0
form-library   -> color-utils   ^2.0.0
Enter fullscreen mode Exit fullscreen mode

Two of your packages want color-utils. They disagree about which one.

That is dependency hell.


Direct vs Transitive

  • Direct: what you typed into package.json
  • Transitive: what your dependencies dragged in behind them

A short direct list usually expands into a much bigger installed tree.

A few dozen direct packages routinely resolve into many hundreds of entries in the lockfile.

Most of the code you ship was chosen by somebody else.


Ranges Are a Promise

^1.4.0 means "any 1.x from 1.4.0 upward". You are trusting each maintainer to judge correctly what counts as a breaking change.

Usually that works.

Sometimes a small release changes a default, and an install that resolves fresh today picks up a version that breaks you with nothing changed on your side.

A committed lockfile is exactly what stops that.


Lockfiles Freeze One Answer

A range describes a set of acceptable versions. A lockfile records which one you actually got, for every package in the tree.

npm install   # reconciles package.json with the lockfile
npm ci        # installs exactly what the lockfile says
Enter fullscreen mode Exit fullscreen mode

Continuous integration should install with npm ci, so every build starts from the tree the lockfile describes.


In One Sentence

Dependency hell is what happens when packages you did not pick disagree about versions of packages you have not heard of.


๐Ÿ”— Enjoying these? Follow for daily ELI5 explanations!

Making complex tech concepts simple, one day at a time.

Top comments (0)