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 depCommon 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
yarn remove: Usage & Common Errorsyarn remove uninstalls a package and updates package.json and yarn.lock. Usage and the "not specified in pack…
pnpm why: Usage, Options & Outputpnpm why shows which dependencies pull in a package and at what version - for debugging duplicates. Usage, -r…
npm ls: Usage, Options & Common Errorsnpm ls prints the installed dependency tree and is the fastest way to debug which version of a package resolv…