The Case for Fewer Dependencies in Your Package

When you add a dependency to an application, you pay for it once. When you add one to a library, every one of your users pays for it, and so do their users. That asymmetry is why I think package authors should be stricter about dependencies than application developers, and why trimming them is one of the most useful maintenance tasks you can do.

What a dependency really costs downstream

A runtime dependency in a published package is not just bytes on disk. It is a commitment that affects people you will never meet:

Which dependencies to look at first

I sort candidates for removal into three rough groups.

Small utilities the platform now provides. Many helpers that once filled gaps in a language's standard library are now built in. In modern JavaScript runtimes, for example, things like deep cloning with structuredClone, fetch, and array helpers such as Array.prototype.flat are available natively. Check the minimum runtime you support before you swap.

Large libraries used for one function. Importing a whole date or utility library to format a single value is a common pattern. Writing ten lines yourself, with tests, is often the better trade for a library.

Things that should be peer or dev dependencies. Build tools, test frameworks and type packages that consumers do not need at runtime belong in devDependencies. A framework your package plugs into usually belongs in peerDependencies.

Removing a dependency without breaking anyone

Dropping a dependency is normally invisible to users, but not always. If your public API returned objects created by that dependency, or re-exported its types, removing it changes your surface. Before removing one, I check:

  1. Does any exported function return, accept or re-export something from this dependency?
  2. Did the dependency add global side effects (polyfills, prototype changes) that users may rely on without knowing?
  3. Is the replacement's behaviour identical on edge cases such as empty input, Unicode and invalid values?

If any answer is yes, treat the removal as a potential breaking change and version it accordingly.

A quick way to see what you ship

Listing your production dependency tree is the first step. With npm, an illustrative check looks like this:

npm ls --omit=dev --all
npm pack --dry-run   # shows which files end up in the tarball

For Python, inspect the dependencies array in pyproject.toml and ask of each entry whether the package would still work without it. Fewer entries make your package easier to install, audit and trust. More on related terms is in the glossary.

Related pages

Subscribe to Our Newsletter

Get new articles by email. No spam, unsubscribe anytime.

No spam. Unsubscribe anytime. We respect your privacy.