{"id":16144,"library":"node-modules-inspector","title":"Node Modules Inspector","description":"Node Modules Inspector is an interactive command-line interface (CLI) and web UI tool designed for comprehensive analysis and visualization of the `node_modules` directory within JavaScript/TypeScript projects. Maintained by Anthony Fu, the package is currently at version 1.4.2 and receives regular updates, as indicated by its recent feature and bugfix releases. It helps developers understand their project's dependency graph, identify installed dependencies, analyze package sizes, detect module types (ESM vs. CJS), and locate duplicates or version conflicts. The tool differentiates itself by offering an interactive UI that can be launched locally or built into a static report for hosting, supporting various package managers including npm, pnpm, and Bun. It is particularly useful for debugging dependency issues, optimizing bundle sizes in large projects or monorepos, and quickly assessing potential vulnerabilities through its report view.","status":"active","version":"1.4.2","language":"javascript","source_language":"en","source_url":"https://github.com/antfu/node-modules-inspector","tags":["javascript","typescript"],"install":[{"cmd":"npm install node-modules-inspector","lang":"bash","label":"npm"},{"cmd":"yarn add node-modules-inspector","lang":"bash","label":"yarn"},{"cmd":"pnpm add node-modules-inspector","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The primary interaction is typically via `npx` or a script, but the `run` function allows programmatic execution of the CLI. The package is ESM-first, so direct CommonJS `require` is not recommended for core modules.","wrong":"const run = require('node-modules-inspector/cli');","symbol":"run","correct":"import { run } from 'node-modules-inspector/cli';\n// Or, for direct CLI usage:\n// npx node-modules-inspector"},{"note":"This symbol, or similar, is inferred for programmatic analysis based on the package's functionality. Named imports are standard for modern TypeScript/ESM libraries. Exact export name might vary, consult source if 'analyzeProject' fails.","wrong":"import analyzeProject from 'node-modules-inspector/core'; // Incorrect default import","symbol":"analyzeProject","correct":"import { analyzeProject } from 'node-modules-inspector/core';\n// For detailed analysis."},{"note":"When importing only types in TypeScript, `import type` is preferred for better tree-shaking and clarity, though `import` works at compile time. This type is for consuming the structured output of the analysis.","wrong":"import { ModuleReport } from 'node-modules-inspector/types'; // Using `import` instead of `import type` for types.","symbol":"ModuleReport","correct":"import type { ModuleReport } from 'node-modules-inspector/types';"}],"quickstart":{"code":"import { analyzeProject } from 'node-modules-inspector/core';\nimport path from 'node:path';\nimport process from 'node:process';\n\nasync function inspectCurrentProject() {\n  const projectPath = process.cwd();\n  console.log(`Analyzing node_modules in: ${projectPath}\\n`);\n\n  try {\n    // The `analyzeProject` function (inferred) would perform the core logic.\n    // In a real scenario, this might return a structured report object.\n    const report = await analyzeProject(projectPath, {\n      // Optional: Specify package manager if not auto-detected\n      packageManager: 'npm',\n      // Optional: Include dev dependencies in the analysis\n      includeDevDependencies: true,\n      // Optional: Filter modules based on criteria\n      filter: (module) => !module.name.startsWith('@types/'),\n    });\n\n    console.log('Analysis Complete! Key Insights:');\n    console.log(`Total unique packages: ${report.packages.length}`);\n    console.log(`Total disk size: ${report.totalSizeHumanReadable}`);\n    console.log(`Duplicate packages found: ${report.duplicates.length}`);\n    console.log(`Modules with known vulnerabilities: ${report.vulnerabilities?.length || 0}`);\n    console.log('\\nTo view the full interactive report, run:');\n    console.log('npx node-modules-inspector');\n\n  } catch (error) {\n    console.error(`Error during analysis: ${error.message}`);\n    console.error('Ensure you run this in a project with a node_modules directory.');\n    console.error('If this error persists, try running `npx node-modules-inspector` directly.');\n  }\n}\n\ninspectCurrentProject();","lang":"typescript","description":"This quickstart demonstrates how to programmatically analyze a project's `node_modules` directory and log summary information."},"warnings":[{"fix":"Prefer `npx node-modules-inspector` for interactive analysis. If integrating programmatically, refer to the package's source or examples for exact API details, as it may evolve.","message":"The `node-modules-inspector` package is primarily designed as a CLI tool with an interactive UI. While it exposes a programmatic API, the most common and feature-rich way to use it is via `npx node-modules-inspector` in your project's root, which launches a local web-based interface for exploration.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"For non-interactive or deployable reports, run `npx node-modules-inspector build`. The output will be in a `.node-modules-inspector` folder which can then be served as static files.","message":"When using `node-modules-inspector` in CI/CD environments or for static reports, remember to use the `build` command (e.g., `npx node-modules-inspector build`). Simply running the inspector without the build command will not generate persistent output for later review or hosting.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure your `node_modules` is in a clean state by running `rm -rf node_modules && [your-package-manager] install` before using the inspector. This helps guarantee an accurate reflection of your project's dependencies.","message":"The tool relies on the structure and content of your `node_modules` directory. Issues with package manager caching, inconsistent installs, or corrupted `node_modules` can lead to incomplete or incorrect analysis reports.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Upgrade to `node-modules-inspector@latest` (or >=1.4.0) to benefit from the integrated vulnerability scanning in the report UI.","message":"The 'vulnerability tab on report view' feature was added in v1.4.0. Users on older versions will not have access to this security analysis capability.","severity":"gotcha","affected_versions":"<1.4.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Ensure you are using correct ESM import paths (e.g., `import { run } from 'node-modules-inspector/cli';`) and that your project supports ESM. For direct CLI usage, prefer `npx node-modules-inspector`.","cause":"Attempting to `require` or `import` a submodule path that does not exist or has been moved, or an incorrect import style for an ESM-first package. This often happens with CommonJS `require` calls.","error":"Error: Cannot find module 'node-modules-inspector/cli'"},{"fix":"Add checks for `report` and its properties being defined before accessing them. Ensure your project has a `node_modules` directory and dependencies are installed. Log the `report` object to inspect its structure if the issue persists.","cause":"This typically occurs when trying to access properties of the analysis report object (e.g., `report.packages.length`) before the analysis is complete or if the property is unexpectedly `undefined` due to an error during analysis or an empty `node_modules` directory.","error":"TypeError: Cannot read properties of undefined (reading 'length') when accessing report data"},{"fix":"Ensure `npm` is correctly installed and its bin directory is in your system's PATH. You can also try installing the package globally first: `npm install -g node-modules-inspector`, then run `node-modules-inspector`.","cause":"The `node-modules-inspector` package is not installed or `npx` cannot locate it in your environment. This might happen if npm's global bin path is not in your system's PATH, or if there's a temporary network issue preventing `npx` from downloading it.","error":"npx node-modules-inspector: command not found"}],"ecosystem":"npm"}