Files

85 lines
1.8 KiB
Plaintext
Raw Permalink Normal View History

2026-08-27 21:09:14 +00:00
---
title: "bun why"
description: "Explain why a package is installed"
---
`bun why` explains why a package is installed in your project by showing the dependency chain that led to it.
## Usage
```bash terminal icon="terminal"
bun why <package>
```
## Arguments
- `<package>`: The name of the package to explain. Supports glob patterns like `@org/*` or `*-lodash`.
## Options
- `--top`: Show only the top-level dependencies instead of the complete dependency tree.
- `--depth <number>`: Maximum depth of the dependency tree to display.
## Examples
Check why a specific package is installed:
```bash terminal icon="terminal"
bun why react
```
```txt
[email protected]
└─ [email protected] (requires ^18.0.0)
```
Check why all packages matching a pattern are installed:
```bash terminal icon="terminal"
bun why "@types/*"
```
```txt
@types/[email protected]
└─ dev [email protected] (requires ^18.0.0)
@types/[email protected]
└─ dev [email protected] (requires ^18.0.0)
```
Show only top-level dependencies:
```bash terminal icon="terminal"
bun why express --top
```
```txt
[email protected]
└─ [email protected] (requires ^4.18.2)
```
Limit the dependency tree depth:
```bash terminal icon="terminal"
bun why express --depth 2
```
```txt
[email protected]
└─ [email protected] (requires ^4.18.2)
└─ [email protected] (requires ^1.20.1)
└─ [email protected] (requires ^1.3.8)
└─ (deeper dependencies hidden)
```
## Understanding the Output
The output shows:
- The package name and version being queried
- The dependency chain that led to its installation
- The type of dependency (dev, peer, optional, or production)
- The version requirement specified in each package's dependencies
For nested dependencies, the command shows the complete dependency tree by default, with indentation indicating the relationship hierarchy.