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 transitiveYou 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.0allow 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
| Ecosystem | Command | What it shows |
|---|---|---|
| npm | npm ls --all | Full installed tree. Without --all it stops at the top level |
| npm | npm explain <package> | Every path from your project to that package |
| pnpm | pnpm why <package> | The packages that require it |
| Yarn | yarn why <package> | Why a package is installed |
| pip | pipdeptree (separate install) | Installed packages as a tree. pipdeptree --reverse --packages <package> shows what requires one |
| uv | uv tree, uv tree --invert | The resolved tree, or the inverted tree showing dependents |
| Poetry | poetry show --tree | Declared dependencies with their own requirements |
| Maven | mvn dependency:tree | Resolved tree with scopes; -Dverbose shows omitted conflicts |
| Gradle | gradle dependencies | Tree per configuration; dependencyInsight --dependency <name> --configuration runtimeClasspath explains one (Java projects default to compileClasspath) |
| Cargo | cargo tree, cargo tree -i <crate> | The crate tree, or the inverted tree for one crate |
| Go | go 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.lockandgo.sumrecord the exact resolved versions. Applications should commit them. - Override a version. npm has
overridesinpackage.json, Yarn hasresolutions, and pnpm haspnpm.overridesinpackage.json, oroverridesinpnpm-workspace.yamlin 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.txtlimits versions of packages without adding them as requirements. - Manage versions in Maven.
dependencyManagementin 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.