Skip to content
Latchkey

yarn why: Usage & Output

Explain why a package is in your dependency tree.

yarn why traces a package back through the dependency graph to show which of your dependencies required it, and at which version.

What it does

Prints the dependency chains that lead to the package - the parents that requested it and the version that resolved. It is the fastest way to find out who pulled in an unexpected package or why two versions coexist.

Common usage

Terminal
yarn why lodash             # who depends on lodash
yarn why @types/node        # trace a transitive type dep

Common CI use: debug a duplicate version

A bundle is bloated or a runtime "two copies of React" bug appears in CI. Run yarn why on the package to see which dependency pins the second version, then add a resolutions entry to force a single version.

Terminal
yarn why react
# then in package.json: "resolutions": { "react": "18.3.1" }

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →