Skip to main content

Overview

The pm why command shows why a package is installed in your project by displaying the dependency chain that requires it.
This command is not supported for npm. It works with pnpm and bun only.

Syntax

Arguments

string
required
The package name to investigate
string[]
Additional arguments passed to the underlying package manager

Examples

Check Why Package is Installed

Output

Check Transitive Dependency

Output

Check Deep Dependency

Output

Use Cases

Debug Unexpected Package

Find out why an unexpected package is installed:

Understand Duplicates

Check why multiple versions exist:

Audit Dependencies

Investigate security vulnerabilities:

Plan Upgrades

Understand dependencies before upgrading:

How It Works

From src/commands/why.ts:10-22:
The command:
  1. Detects your package manager
  2. Checks if it’s npm (not supported)
  3. Passes arguments to pnpm why or bun why
  4. Displays the dependency tree

Package Manager Support

npm users can use npm ls <package> as an alternative, though it provides different output format.

Alternative for npm

If you’re using npm:
This shows where the package is used, but with different formatting.

Understanding Output

The output typically shows:
  1. Package version - The installed version
  2. Dependency type - Whether it’s in dependencies, devDependencies, etc.
  3. Dependency chain - The tree of packages that require it
  4. Version ranges - The semver ranges that satisfied the requirement

Example Output Explained

This tells you:
  • React 18.2.0 is installed
  • It’s a direct dependency of your app
  • react-dom requires react ^18
  • ui-library also requires react ^18.0.0

Common Scenarios

Find Dependency Source

Debug Version Conflicts

Identify Bloat

Security Audit

Workflow Examples

Remove Unused Dependency

1

Check Usage

2

If No Direct Use

If it’s only a transitive dependency, consider alternatives
3

If Direct Dependency

Remove safely:

Investigate Duplicate

1

Check Why Installed

2

Review Version Ranges

Check if dependencies can use the same version
3

Update Dependencies

Align versions to remove duplicates:
  • pm ls - List installed dependencies
  • pm remove - Remove dependencies
  • pm up - Update dependencies