yarn why — Yarn CLI reference

Display the reason why a package is needed

Docs/Reference/CLI/why

yarn why

Display the reason why a package is needed

yarn why <PATTERN>

This command prints the exact reasons why a package appears in the dependency tree.

The package can be followed by a semver range (<package>@<range>), in which case only the instances of the package whose resolved version satisfies the range are reported. This is particularly useful when trying to find out why your project depends on older versions of a package. The range must be a valid semver range; protocols (npm:^1.0.0) and tags (latest) aren’t accepted. The package name itself can be a glob pattern (@babel/*).

A dependency is reported when the name matches the one it is declared under or the one of the package it resolved to. The two differ for aliases (my-lodash@npm:lodash@^4) and for packages installed through a platform-specific variant (@yarnpkg/node, which resolves to @yarnpkg/node-linux-x64 and the like).

By default, it will print all packages that directly depend on the specified package. If you want to see all transitive paths that lead to the package (going through all workspaces), use the -R,--recursive flag.

Note that the recursive display is optimized to avoid printing the same package subtree multiple times. If you see a package without children in one branch, it means its subtree was already printed elsewhere in the tree.

#--recursive, -Rboolean

List all dependency paths from each workspace

#--jsonboolean

Format the output as an NDJSON stream

#--peersboolean

Also print peer dependencies that match the specified name

Examples#

Explain why lodash is used in your project

yarn why lodash

Explain why version 3.3.1 of lodash is in your project

yarn why lodash@3.3.1

Explain why versions 3.x of lodash are in your project

yarn why lodash@^3

Print all the dependency paths that lead to lodash

yarn why lodash -R