Categories

Import Path Extractor

Extract all import/require paths from JavaScript/TypeScript code

Import Path Extractor

This tool extracts all import and require statements from JavaScript/TypeScript code:

Supported Import Types:

  • ES6 Imports: import ... from 'path'
  • TypeScript Type-only Imports: import type ... from 'path'
  • Dynamic Imports: import('path')
  • CommonJS Requires: require('path')
  • Export From: export ... from 'path'

Path Categories:

  • Package Imports: node_modules packages (e.g., 'react', 'lodash')
  • Relative Imports: Local files (e.g., './utils', '../components')
  • Absolute Imports: Absolute paths (e.g., '/src/config')

Features:

  • Line number tracking for each import
  • Deduplication of import paths
  • Grouping by import type
  • Filtering by package/relative paths
  • Support for both JavaScript and TypeScript

Example Usage:

import React from 'react'
import { useState } from 'react'
import type { User } from './types'
import * as lodash from 'lodash'
const utils = require('./utils')
import('./lazyModule').then(module => {})
export { Component } from './Component'

Use Cases:

  • Analyze code dependencies
  • Find all imported modules
  • Identify external dependencies
  • Refactor import statements
  • Audit code for unused imports

Include imports from node_modules (package imports)

Include relative file imports (./, ../)

Group results by import type (ES6, CommonJS, Dynamic, etc.)

Key Facts

Category
Development
Input Types
textarea, checkbox
Output Type
json
Sample Coverage
4
API Ready
Yes

Overview

The Import Path Extractor is a tool that extracts all import and require statements from JavaScript or TypeScript code. It supports ES6 imports, TypeScript type-only imports, dynamic imports, CommonJS requires, and export-from statements, providing a clear view of code dependencies.

When to Use

  • When analyzing dependencies in a JavaScript or TypeScript project to understand module relationships.
  • To identify all external packages and relative file imports for auditing or documentation purposes.
  • During code refactoring to locate and update import paths efficiently.

How It Works

  • Paste your JavaScript or TypeScript code into the input field.
  • Configure options to include or exclude node modules and relative paths, and choose to group results by import type.
  • The tool parses the code, extracts all import and require statements, and tracks line numbers.
  • Results are displayed in JSON format, with deduplicated paths and optional grouping for easy analysis.

Use Cases

Analyzing project dependencies to map module relationships and identify external packages.
Refactoring code by extracting and updating import paths across multiple files.
Auditing for unused imports to reduce bundle size and improve code cleanliness.

Examples

1. Extracting Dependencies from a React Component

Frontend Developer
Background
A developer is reviewing a React component file to list all imported modules for documentation.
Problem
Manually scanning the code for import statements is tedious and prone to errors.
How to Use
Paste the component code into the tool and enable 'Include Node Modules' to capture all package imports.
Outcome
The tool outputs a JSON list of import paths like 'react' and './utils', with line numbers for quick reference.

2. Auditing TypeScript Code for Import Cleanup

Software Engineer
Background
An engineer is optimizing a TypeScript codebase before deployment to remove unnecessary imports.
Problem
Unused imports clutter the code and may increase the final bundle size.
How to Use
Upload the TypeScript file and configure the tool to group results by import type for systematic review.
Outcome
Identifies all import statements, enabling the engineer to pinpoint and remove unused ones efficiently.

Try with Samples

development

Related Hubs

FAQ

What import types does this tool support?

It supports ES6 imports, TypeScript type-only imports, dynamic imports, CommonJS requires, and export-from statements.

Can I filter the extracted paths?

Yes, you can toggle options to include or exclude node modules and relative paths based on your needs.

What output format is provided?

The results are in JSON format, making it easy to parse, integrate, or further process the data.

Does it handle large codebases?

Yes, it efficiently processes large files with features like deduplication and line number tracking for accuracy.

Is TypeScript code fully supported?

Yes, the tool works seamlessly with both JavaScript and TypeScript, including type-only imports.

API Documentation

Request Endpoint

POST /en/api/tools/import-path-extractor

Request Parameters

Parameter Name Type Required Description
code textarea Yes -
includeNodeModules checkbox No Include imports from node_modules (package imports)
includeRelativePaths checkbox No Include relative file imports (./, ../)
groupByType checkbox No Group results by import type (ES6, CommonJS, Dynamic, etc.)

Response Format

{
  "key": {...},
  "metadata": {
    "key": "value"
  },
  "error": "Error message (optional)",
  "message": "Notification message (optional)"
}
JSON Data: JSON Data

AI MCP Documentation

Add this tool to your MCP server configuration:

{
  "mcpServers": {
    "elysiatools-import-path-extractor": {
      "name": "import-path-extractor",
      "description": "Extract all import/require paths from JavaScript/TypeScript code",
      "baseUrl": "https://elysiatools.com/mcp/sse?toolId=import-path-extractor",
      "command": "",
      "args": [],
      "env": {},
      "isActive": true,
      "type": "sse"
    }
  }
}

You can chain multiple tools, e.g.: `https://elysiatools.com/mcp/sse?toolId=png-to-webp,jpg-to-webp,gif-to-webp`, max 20 tools.

If you encounter any issues, please contact us at [email protected]