Skip to main content

Description

Compares package.json dependencies with actual imports in your codebase to identify potentially unused packages. This helps clean up your dependencies and reduce bundle size.

Usage

rev-dep node-modules unused [flags]

Examples

# Find unused dependencies, excluding type definitions
rev-dep node-modules unused --exclude-modules=@types/*

# Count unused modules
rev-dep node-modules unused --count

# Find unused packages with verbose output
rev-dep node-modules unused --verbose

# Analyze from specific entry points
rev-dep node-modules unused -p src/main.ts -p src/worker.ts

Flags

--condition-names
strings
List of conditions for package.json imports resolution (e.g. node, imports, default)
-n, --count
boolean
Only display the count of modules
-c, --cwd
string
default:"$PWD"
Working directory for the command
-p, --entry-points
strings
Entry point file(s) to start analysis from (default: auto-detected)
-e, --exclude-modules
strings
List of modules to exclude from the output
-b, --files-with-binaries
strings
Additional files to search for binary usages. Use paths relative to cwd
-m, --files-with-node-modules
strings
Additional files to search for module imports. Use paths relative to cwd
--follow-monorepo-packages
strings
Enable resolution of imports from monorepo workspace packages. Pass without value to follow all, or pass package names
-h, --help
boolean
Help for unused
-t, --ignore-type-imports
boolean
Exclude type imports from the analysis
-i, --include-modules
strings
List of modules to include in the output
--package-json
string
default:"./package.json"
Path to package.json
--pkg-fields-with-binaries
strings
Additional package.json fields to check for binary usages
--tsconfig-json
string
default:"./tsconfig.json"
Path to tsconfig.json
-v, --verbose
boolean
Show warnings and verbose output
--zero-exit-code
boolean
Use this flag to always return zero exit code

Use Cases

Dependency Cleanup

Identify dependencies listed in package.json that are no longer used in your code.

Reduce Bundle Size

Remove unused packages to reduce your project’s bundle size and installation time.

CI/CD Integration

Use --zero-exit-code in CI pipelines to report unused dependencies without failing builds.
When analyzing unused dependencies, consider excluding type-only packages with --exclude-modules=@types/* as they may be needed for development but not imported directly in code.

Build docs developers (and LLMs) love