> ## Documentation Index
> Fetch the complete documentation index at: https://bun.ll1025.cn/llms.txt
> Use this file to discover all available pages before exploring further.

# bun why

> 解释为什么安装了某个包

`bun why` 通过显示导致某个包被安装的依赖链，来解释为什么该包存在于你的项目中。

## 用法

```bash terminal icon="terminal" theme={null}
bun why <package>
```

## 参数

* `<package>`：要解释的包名称。支持 glob 模式，如 `@org/*` 或 `*-lodash`。

## 选项

* `--top`：仅显示顶层依赖，而不是完整的依赖树。
* `--depth <number>`：显示的依赖树的最大深度。

## 示例

检查为什么安装了特定包：

```bash terminal icon="terminal" theme={null}
bun why react
```

```txt theme={null}
react@18.2.0
  └─ my-app@1.0.0 (需要 ^18.0.0)
```

检查为什么所有匹配模式的包都被安装了：

```bash terminal icon="terminal" theme={null}
bun why "@types/*"
```

```txt theme={null}
@types/react@18.2.15
  └─ dev my-app@1.0.0 (需要 ^18.0.0)

@types/react-dom@18.2.7
  └─ dev my-app@1.0.0 (需要 ^18.0.0)
```

仅显示顶层依赖：

```bash terminal icon="terminal" theme={null}
bun why express --top
```

```txt theme={null}
express@4.18.2
  └─ my-app@1.0.0 (需要 ^4.18.2)
```

限制依赖树深度：

```bash terminal icon="terminal" theme={null}
bun why express --depth 2
```

```txt theme={null}
express@4.18.2
  └─ express-pollyfill@1.20.1 (需要 ^4.18.2)
     └─ body-parser@1.20.1 (需要 ^1.20.1)
     └─ accepts@1.3.8 (需要 ^1.3.8)
        └─ (更深层的依赖已隐藏)
```

## 理解输出

输出显示：

* 被查询的包名和版本
* 导致其被安装的依赖链
* 依赖类型（dev、peer、optional 或 production）
* 每个包依赖中指定的版本要求

对于嵌套依赖，命令默认显示完整的依赖树，缩进表示层级关系。
