A fast CLI tool to find unused exports in Node.js and TypeScript projects. It scans your git repository for exported functions, that are not imported anywhere else in your codebase.
go install github.com/aherve/unused-node-exports/v3@latest
Precompiled binaries are available on the releases page
See all available options with:
unused-node-exports --help
unused-node-exports scan ./my-project -e .ts,.tsx -p my/lib/ -o unused.csv
unused-node-exports scan . -p my-folder --autofix
- Using
git grep, find all files that containexport [async] [function|const]statements and extract the exported names. - Using
git grep, find all files that containimportstatements, and extract the imported names. - Compare the two sets and identify exported names that are not imported anywhere else in the code
This process is extremely fast and works on large codebases that export sub-modules such as turbo-repo or monorepo. However, it may not catch all edge cases. Performances are prioritized over perfection.
I created this tool to work on a large codebase where the existing npm tools I tried quickly run out of memory.
