npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

unused-import-scanner

v1.0.1

Published

Find unused files and imports in JavaScript/TypeScript projects. Supports React, React Native, Next.js, and generic JS projects.

Readme

unused-import-scanner

A zero-dependency CLI tool that finds unused files and unused imports in JavaScript/TypeScript projects. Supports React, React Native, Next.js, and generic JS/TS projects.

Built by Makdos — software products crafted for modern teams.

Features

  • Detects unused files — source files that are never imported anywhere
  • Detects unused imports — imported identifiers that are never referenced in the file
  • Automatically identifies your project type (React, React Native, Next.js, generic)
  • Resolves TypeScript/JavaScript path aliases (@/components, ~, etc.) from tsconfig.json / jsconfig.json
  • Supports all import styles: named, default, namespace, dynamic import(), require()
  • Zero runtime dependencies — uses only Node.js built-ins
  • Can also be used programmatically as a library

Installation

Global (recommended for CLI usage)

npm install -g unused-import-scanner

Local (as a dev dependency)

npm install --save-dev unused-import-scanner

CLI Usage

# Scan the current directory
unusedfinder

# Scan a specific project directory
unusedfinder /path/to/your/project

# Output results as a JSON report (unused-report.json)
unusedfinder --json

# Combine path and JSON output
unusedfinder /path/to/your/project --json

Example output

Analyzing REACT project...

2 unused file(s) found:

components/
   • components/OldButton.tsx
   • components/LegacyModal.tsx

Unused imports found in 3 file(s):

src/screens/Home.tsx
   • formatDate (line 4) - from '../utils/date'
   • colors (line 5) - from '../constants/theme'

Summary:
   Project type: react
   Total files: 47
   Unused files: 2
   Files with unused imports: 3
   Total unused imports: 5

Tips:
   • Unused helpers can be removed by tree-shaking.

JSON report format

Running with --json writes unused-report.json to the scanned project root:

{
  "projectType": "react",
  "totalFiles": 47,
  "unusedFiles": [
    "components/OldButton.tsx",
    "components/LegacyModal.tsx"
  ],
  "unusedImports": [
    {
      "file": "src/screens/Home.tsx",
      "imports": [
        { "name": "formatDate", "type": "named", "from": "../utils/date", "line": 4 },
        { "name": "colors", "type": "named", "from": "../constants/theme", "line": 5 }
      ]
    }
  ]
}

Programmatic Usage

You can also import and use the scanner directly in your code:

import { UniversalUnusedFinder } from 'unused-import-scanner';

// Basic usage — returns the analysis result
const finder = new UniversalUnusedFinder({
  projectRoot: '/path/to/your/project',
});

const result = finder.analyze();

console.log(result.projectType);   // 'react' | 'react-native' | 'nextjs' | 'generic'
console.log(result.totalFiles);    // number
console.log(result.unusedFiles);   // string[]
console.log(result.unusedImports); // Array<{ file: string; imports: ImportInfo[] }>
// With options
const finder = new UniversalUnusedFinder({
  projectRoot: '/path/to/your/project',
  silent: true, // suppress all console output
});

// Print results to console and optionally write JSON
finder.printResults(true); // true = write unused-report.json

Types

type ProjectType = 'react-native' | 'nextjs' | 'react' | 'generic';

interface FinderOptions {
  projectRoot?: string; // defaults to process.cwd()
  silent?: boolean;     // suppress console output, default false
}

interface AnalysisResult {
  projectType: ProjectType;
  totalFiles: number;
  unusedFiles: string[];
  unusedImports: Array<{
    file: string;
    imports: ImportInfo[];
  }>;
}

interface ImportInfo {
  name: string;
  type: 'default' | 'named' | 'namespace' | 'side-effect' | 'require' | 'dynamic';
  from: string;
  line: number;
  original?: string; // for aliased imports: import { Foo as Bar }
}

How it works

  1. Project detection — reads package.json to determine project type and select appropriate scan directories and entry points
  2. File collection — recursively scans configured directories, skipping node_modules, dist, test files, and framework entry points
  3. Import graph traversal — builds a graph of all imports across all files to find which files are reachable from entry points
  4. Unused file detection — files not reachable from any entry point are marked as unused
  5. Unused import detection — for each file, extracts all imported identifiers and checks whether they appear in the file body

Path alias resolution

The tool reads tsconfig.json or jsconfig.json and resolves configured paths and baseUrl. For example:

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@/*": ["src/*"],
      "@components/*": ["src/components/*"]
    }
  }
}

Imports like import Button from '@components/Button' are correctly resolved.


Supported file types

.js .jsx .ts .tsx

Ignored directories

node_modules .git .next build dist .expo coverage .parcel-cache

Ignored file patterns

Files containing .test., .spec., _test., _spec. in their name are skipped.


Requirements

  • Node.js >= 16.0.0

Authors

Made at Makdos

License

MIT