pnpm why

显示依赖于指定包的所有包。

pnpm why <pkg>...

例如:

pnpm why "@babel/*"

A package name or --find-by is required. Without either, the command fails with ERR_PNPM_MISSING_PACKAGE_NAME.

输出结果是一个反向依赖关系树:搜索到的软件包出现在根节点,其依赖项作为分支,一直延伸到工作区根节点。

输出结果中会去除重复的子树,并显示为“去重后”。

配置项#

--recursive, -r#

显示子目录下每个包中指定包的依赖关系树,或在工作空间内执行时显示每个工作空间包中指定包的依赖关系树。

--json#

以 JSON 格式显示信息。 Dependent nodes include a requires field containing the declared dependency specifier, when available.

--long#

输出详细信息。

--parseable#

显示可解析的输出而不是树形视图。

--global, -g#

Inspect packages in the global install directory instead of in the current project.

--ranges#

Show the version range that each direct dependent declares for the package, in place of the tree. Dependents that declare the same range are listed under it, and each installed version gets its own section:

esbuild
  Installed: 0.28.1
  Wanted:
    ^0.28.0:
      vite@6.1.0
    ~0.28.0:
      tsx@4.23.1

A dependent whose package.json cannot be read is listed under <unknown>.

--prod, -P, --production#

Only display the dependency tree for packages in dependencies and optionalDependencies.

--dev, -D#

仅显示在 devDependencies 中的包依赖关系树。

--no-optional#

显示除 optionalDependencies 之外的包的依赖关系图。

--optional#

Include packages from optionalDependencies.

--depth <number>#

仅显示特定深度内的依赖关系。

--exclude-peers#

Leave out the packages that are reached only as a resolved peer dependency. A package that is also a regular dependency of some project or package stays.

--filter <package_selector>#

阅读更多有关过滤的内容。

--find-by <finder_name>#

使用 .pnpmfile.mjs 中定义的 [查找器函数] 按名称以外的属性匹配依赖项。