Glossary · Structure and dead code

What is a transitive dependency?

A transitive dependency is a package your project uses indirectly: you never declared it, but one of your direct dependencies requires it, so the package manager installs it too. If your app depends on A and A depends on B, B is transitive. Most installed packages in a typical project are transitive.

Last reviewed: November 2026

Also called Indirect dependency, Nested dependency, Dependency of a dependency

In depth Building a dependency graph for any codebase: how imports are parsed and resolved per language, then ranked and clustered.

Direct and transitive dependencies

Say your app declares one dependency, web-server. That package needs router and logger, and router needs path-utils. The tree looks like this:

your-app
  web-server        direct
    router          transitive
      path-utils    transitive
    logger          transitive

You wrote one line in your manifest. The package manager resolved four packages and wrote all of them to the lock file. The depth is unlimited, so a small manifest can pull in hundreds of packages. That is the usual case: the declared list is short and the installed list is long.

The term also has a database meaning, covered below. The rest of this page is about software packages.

Why transitive dependencies matter

  • Version conflicts. Two direct dependencies can need different versions of the same package. This is the diamond dependency problem: your app needs A and B, both need C, and A wants C 1.x while B wants C 2.x. Ecosystems solve it differently. npm can install both copies side by side. Python and Java load one copy, so something has to give.
  • Security. A vulnerable package three levels down is still running in your build. Log4Shell (CVE-2021-44228) in log4j-core is the standard example, since many applications used it only through other libraries.
  • Size and build time. Each package is downloaded in CI, shipped in images and scanned. You did not choose any of them, but you pay for all of them.
  • Reproducibility. Ranges such as ^1.2.0 allow new transitive versions on every fresh install. The lock file is what freezes them.
  • Maintenance. When a transitive package is abandoned, you find out through an audit warning for something you never imported.

How to list transitive dependencies

EcosystemCommandWhat it shows
npmnpm ls --allFull installed tree. Without --all it stops at the top level
npmnpm explain <package>Every path from your project to that package
pnpmpnpm why <package>The packages that require it
Yarnyarn why <package>Why a package is installed
pippipdeptree (separate install)Installed packages as a tree. pipdeptree --reverse --packages <package> shows what requires one
uvuv tree, uv tree --invertThe resolved tree, or the inverted tree showing dependents
Poetrypoetry show --treeDeclared dependencies with their own requirements
Mavenmvn dependency:treeResolved tree with scopes; -Dverbose shows omitted conflicts
Gradlegradle dependenciesTree per configuration; dependencyInsight --dependency <name> --configuration runtimeClasspath explains one (Java projects default to compileClasspath)
Cargocargo tree, cargo tree -i <crate>The crate tree, or the inverted tree for one crate
Gogo mod graph, go mod why -m <module>All module edges, or why a module is needed

Read the reverse view first when you are asking why a package is there. It names the direct dependency to change.

How to control transitive dependencies

  • Commit the lock file. package-lock.json, pnpm-lock.yaml, yarn.lock, uv.lock, poetry.lock, Cargo.lock and go.sum record the exact resolved versions. Applications should commit them.
  • Override a version. npm has overrides in package.json, Yarn has resolutions, and pnpm has pnpm.overrides in package.json, or overrides in pnpm-workspace.yaml in newer versions. Use these to force a patched version of a package you do not own, and remove the override when the parent catches up.
  • Constrain in Python. pip install -c constraints.txt -r requirements.txt limits versions of packages without adding them as requirements.
  • Manage versions in Maven. dependencyManagement in a POM fixes the version for a package wherever it appears in the tree, and a bill of materials (BOM) imports a vetted set. <exclusions> drops a transitive package from one dependency.
  • Upgrade the parent. Dependabot and Renovate open pull requests for direct dependencies, which usually moves the transitive ones along.
  • Remove what you do not use. Dropping an unused direct dependency also drops its subtree. See zombie dependencies.

Package level and code level

Everything above is the package graph, built from manifests and lock files. Your own source has the same structure. File A imports B, B imports C, so A depends on C transitively, and a change in C can break A. Following those edges outward from a file gives its blast radius. Both graphs are kinds of dependency graph, and they disagree in practice: a package can be installed and never imported.

Transitive dependency in databases

In relational design, a transitive dependency is a chain of functional dependencies between columns: A determines B, B determines C, so A determines C through B. In an orders table with order_id, customer_id and customer_city, order_id determines customer_id and customer_id determines customer_city. The city depends on the order only through the customer.

Third normal form (3NF) forbids this when B is not a key. The fix is to move customer_city into a customers table keyed by customer_id. A partial dependency is the second normal form (2NF) counterpart: a column depends on only part of a composite key, not on the whole key. Partial dependencies are removed first, transitive ones next.

How repowise handles transitive dependencies

repowise builds the code-level graph. It parses imports across the repository and follows them to answer which files sit downstream of a change, which feeds get_risk and the architecture map. It does not replace npm audit or your lock file for package-level questions. Use both views: the package tree for what you ship, the import graph for what your code reaches. How the graph is built is in building a dependency graph for any codebase.

FREQUENTLY ASKED

Transitive dependency: questions

What is the difference between a direct and a transitive dependency?

A direct dependency is one you declare yourself in the manifest, such as package.json or pom.xml. A transitive dependency is pulled in by one of those. You can edit the first kind freely. The second kind is chosen by the package that needs it, within the version range that package allows.

How do I see my transitive dependencies?

Run your ecosystem's tree command: npm ls --all, pnpm why, yarn why, pipdeptree, uv tree, poetry show --tree, mvn dependency:tree, gradle dependencies, cargo tree or go mod graph. The tree shows who requires each package and at which version.

Can I update or remove a transitive dependency?

You cannot remove it while something still requires it. You can pin its version with npm overrides, yarn resolutions, pnpm overrides, pip constraints or Maven dependencyManagement. The cleaner fix is to upgrade or drop the direct dependency that brings it in.

Are transitive dependencies a security risk?

Yes, because vulnerabilities arrive through them. Log4Shell reached many affected applications through libraries that bundled log4j-core, not through a line in their own manifest. Audit tools such as npm audit, pip-audit and OSV-Scanner scan the full tree for this reason.

Is transitive dependency allowed in 3NF?

No. Third normal form removes transitive functional dependencies between columns: if A determines B and B determines C, and B is not a key, C should move to its own table keyed by B. The database meaning is unrelated to packages.

See it on your own repository.

Index a repository free and read the result for your own code and history. Or explore a live repo first.