Clean up unused npm deps!

Finds unused npm packages and helps you sweep them away โ€” safely.

$ deps-janitor

๐Ÿงน Checking the halls for messes...

๐Ÿ—‚๏ธ Found 11 files to inspect

๐Ÿงน deps-janitor reporting for duty!

๐Ÿข Building: deps-janitor

๐Ÿ› ๏ธ Tools: npm

๐Ÿ” Time to sweep for dusty packages...

๐Ÿงฝ Dusting off: @types/react

๐Ÿงฝ Dusting off: @types/react-dom

๐Ÿงฝ Dusting off: eslint-config-next

๐Ÿงน Swept through 10 packages

๐Ÿ—‚๏ธ Found 3 dusty packages collecting cobwebs:

1. ๐Ÿ“ฆ react-dom

2. ๐Ÿ“ฆ eslint-config-next

3. ๐Ÿ“ฆ tailwindcss

๐Ÿงน Clean sweep? Remove all dusty packages? (y/n): n

found 0 vulnerabilities

โœจ tailwindcss swept away!

๐Ÿงน Cleaning Report:

๐Ÿ—‘๏ธ Tossed: 1

โœจ Kept tidy: 7

โญ๏ธ Skipped: 2

โœจ All clean! Building's looking sharp.

Features

Everything you need to keep your dependency list tidy

Smart Sweeping
Finds dependencies that are truly unused โ€” not just suspicious-looking ones
Thorough Inspection
Understands ES imports, CommonJS, dynamic imports, and subpaths
VIP Treatment
Knows when to leave important tools alone (configs, build tools, types)
Friendly Chat
Always asks before removing anything โ€” no surprise cleanups
Multi-Tool Support
Plays nicely with npm, yarn, and pnpm
Building Aware
Handles basic monorepos without getting confused
Inspection Mode
Dry-run mode lets you preview the mess before cleaning it
Quick Work
Caches files so cleanup stays fast, even in big projects

Usage

One command. A cleaner dependency list.

Basic Usage

deps-janitor

Dry Run

deps-janitor --dry-run

Preview what would be removed

Debug Mode

deps-janitor --debug

Show detailed analysis

As npm script

{ "scripts": { "cleanup-deps": "deps-janitor" } }

Configuration

Want deps-janitor to ignore certain packages? Drop a .cleanupdepsrc file in your project root:

{ "ignore": ["eslint", "prettier"], "ignorePatterns": ["@types/*", "*-loader"] }
ignore: Array of package names to always keep (exact matches)
ignorePatterns: Array of glob patterns for packages to ignore (supports wildcards)

๐Ÿ’ก Tip: Start with the included .cleanupdepsrc.example, then tweak it as needed.

How It Works

No guesswork. Just careful inspection and polite questions.

  1. File Scanning: Walks through your project files (skipping the usual junk)
  2. Import Analysis: Looks for real usage across common patterns:
    • ES6 imports: import ... from 'package'
    • CommonJS: require('package')
    • Dynamic imports: import('package')
    • Subpath imports: from 'package/subpath'
  3. Special Cases: Recognizes configs, build tools, and setup-only packages
  4. Script Analysis: Checks npm scripts for hidden usage
  5. Interactive Removal: Nothing gets removed without your approval