Find and remove unused exports - clean up dead code from your codebase
npm install exports-cleanup> Find unused exports in your codebase - clean up dead code and reduce bundle size


You export 100 functions. Only 20 are actually used. Dead code bloats your bundle.
exports-cleanup scans your codebase, tracks all imports, and finds exports that are never used anywhere.
- Fast scanning - Uses regex-based parsing for speed
- Bundle size estimation - Shows potential savings in KB
- TypeScript + JavaScript - Works with .ts, .tsx, .js, .jsx, .mjs
- Type-aware - Optionally include/exclude type exports
- CI/CD ready - Exit code 1 when unused exports found
- Zero config - Just run it
``bashRun directly with npx (recommended)
npx exports-cleanup
Usage
$3
`bash
Scan current directory
npx exports-cleanupScan specific directory
npx exports-cleanup ./srcCompact output
npx exports-cleanup --compact
`$3
`bash
Also check type and interface exports
npx exports-cleanup --include-types
`$3
`bash
Show used exports too
npx exports-cleanup --show-used
`Example Output
`
π Unused Exports (47 found):Summary:
Total exports: 120
Unused: 47
Used: 73
Potential savings: 23.4 KB
π src/utils/helpers.ts
β formatDate() [function]
Line 12 - exported but never imported
β calculateTax() [function]
Line 45 - exported but never imported
β DEPRECATED_CONSTANT [const]
Line 78 - exported but never imported
π src/utils/validation.ts
β validateEmail() [function]
Line 5 - exported but never imported
β validatePhone() [function]
Line 23 - exported but never imported
ββββββββββββββββββββββββββββββββββββββββββββββββββ
Potential bundle reduction: 23.4 KB
π‘ Tips:
β’ Remove unused exports to reduce bundle size
β’ Some exports may be used dynamically (check manually)
β’ Entry points and public APIs may show as "unused"
ββββββββββββββββββββββββββββββββββββββββββββββββββ
Cleaned up dead code? Consider supporting:
β https://buymeacoffee.com/willzhangfly
`$3
`
π Found 47 unused exports: src/utils/helpers.ts
formatDate, calculateTax, DEPRECATED_CONSTANT
src/utils/validation.ts
validateEmail, validatePhone
src/components/OldButton.tsx
OldButton, OldButtonProps
Potential savings: 23.4 KB
`Comparison with Alternatives
| Feature | exports-cleanup | TypeScript | ESLint | ts-prune | knip |
|---------|---------------|------------|--------|----------|------|
| Find unused exports | β
| β | β | β
| β
|
| Bundle size estimate | β
| β | β | β | β |
| Zero config | β
| β | β | β οΈ | β |
| Fast | β
| β
| β
| β | β οΈ |
| CI/CD exit codes | β
| β
| β
| β οΈ | β
|
| Actively maintained | β
| β
| β
| β (2021) | β
|
CLI Options
`
Usage: exports-cleanup [options] [path]Arguments:
path Directory to scan (default: ".")
Options:
--json Output results as JSON
--compact Compact output format
--include-types Include type and interface exports
--show-used Also show used exports
--ignore Additional patterns to ignore (comma-separated)
-V, --version Output version number
-h, --help Display help
`CI/CD Integration
`yaml
GitHub Actions
- name: Check for unused exports
run: npx exports-cleanup
# Exits with code 1 if unused exports foundWith threshold (using jq)
- name: Check unused exports count
run: |
npx exports-cleanup --json > unused.json
COUNT=$(cat unused.json | jq '.unusedExports')
if [ "$COUNT" -gt 10 ]; then
echo "Too many unused exports: $COUNT"
exit 1
fi
`Programmatic Usage
`typescript
import { analyzeExports } from 'exports-cleanup';const result = await analyzeExports('./src', {
includeTypes: false,
exclude: ['*/.test.ts'],
});
console.log(
Found ${result.unusedExports} unused exports);
console.log(Potential savings: ${result.estimatedSavings} bytes);// Get unused export names
for (const file of result.files) {
for (const exp of file.exports) {
if (exp.isUnused) {
console.log(
${exp.export.name} in ${file.file});
}
}
}
`False Positives
Some exports may appear unused but are actually used:
1. Entry points - Main exports used by consumers of your package
2. Dynamic imports -
import() expressions aren't always detected
3. Re-exports - export * from './module'
4. Framework conventions - Next.js pages, React components loaded by name
5. Public APIs - Exports meant for external useReview results manually before removing exports.
Ignored by Default
-
node_modules/
- dist/, build/
- .next/
- coverage/
- *.d.ts (declaration files)
- .test., .spec.
- __tests__/`- Node.js 18.0.0 or higher
This project is maintained in my free time. If it helped clean up your codebase, I'd really appreciate your support:
- β Star the repoβit helps others discover this tool
- π’ Share with your team or on social media
- π Report bugs or suggest features
- β Buy me a coffee if you'd like to support development
Thank you to everyone who has contributed, shared feedback, or helped spread the word!
MIT
---
Made with β€οΈ for cleaner codebases