Registry / serialization / parse-imports-exports

parse-imports-exports

JSON →
library0.2.4jsnpmunverified

parse-imports-exports is a JavaScript/TypeScript library designed for fast and easy parsing of ECMAScript and TypeScript import and export declarations. It currently stands at version 0.2.4, indicating it is in active development and pre-1.0, so the API might evolve. The library focuses on extracting structured information about module dependencies from syntactically correct and well-formatted code, supporting both standard ES module syntax and TypeScript-specific constructs like `import type` and `export type`. It is optimized for efficiency and is not a full Abstract Syntax Tree (AST) parser, but rather targets specific module-related statements, including dynamic `import()` and `require()` calls.

npm install parse-imports-exports
INSTALL
IMPORT
SIG · PARSE-IMPORTS-EXPO
P
parse-imports-exports
serializationjavascriptv0.2.4
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parseImportsExports
import { parseImportsExports } from 'parse-imports-exports';
const parseImportsExports = require('parse-imports-exports');
While the library can parse CommonJS `require` statements, it is itself an ESM-first package shipping TypeScript types, so ESM `import` is the idiomatic usage.
ImportExportResult
import type { ImportExportResult } from 'parse-imports-exports';
import { ImportExportResult } from 'parse-imports-exports';
This is a type definition for the parsed output structure. Use `import type` to avoid bundling unnecessary runtime code in environments that support it.
All symbols at once
import { parseImportsExports, ImportExportResult } from 'parse-imports-exports';
Multiple named exports can be imported in a single statement.

Demonstrates how to use `parseImportsExports` to analyze a TypeScript/ECMAScript source string and extract a detailed breakdown of all import, export, and re-export declarations, including dynamic imports and CommonJS `require` statements.

import { parseImportsExports } from 'parse-imports-exports'; const source = ` /** * Imports. */ import {foo as baz, type Bar} from 'Qux'; import Foo, * as foo from 'Qux'; const dynamicQux = await import('Qux'); const commonJSQux = require('Qux'); import type {Foo as Baz, Bar} from 'Qux'; /** * Reexports. */ export {foo as baz, type Bar} from 'Qux'; export * as foo from 'Qux'; export * from 'Qux'; /** * Exports. */ export default 42; export const myVar = 2; export type T = number; `; const importsExports = parseImportsExports(source); console.log(JSON.stringify(importsExports, null, 2)); /* Example output (indices may vary): { "namedImports": { "Qux": [ { "start": 42, "end": 83, "names": { "baz": { "by": "foo" } }, "types": { "Bar": {} } } ] }, "namespaceImports": { "Qux": [ { "start": 85, "end": 117, "namespace": "foo", "default": "Foo" } ] }, "dynamicImports": { "Qux": [ { "start": 129, "end": 165 } ] }, "requires": { "Qux": [ { "start": 177, "end": 206 } ] }, "typeNamedImports": { "Qux": [ { "start": 218, "end": 251, "names": { "Baz": { "by": "Foo" } }, "types": { "Bar": {} } } ] }, "namedReexports": { "Qux": [ { "start": 279, "end": 320, "names": { "baz": { "by": "foo" } }, "types": { "Bar": {} } } ] }, "namespaceReexports": { "Qux": [ { "start": 322, "end": 349, "namespace": "foo" } ] }, "wildcardReexports": { "Qux": [ { "start": 351, "end": 371 } ] }, "defaultExports": [ { "start": 399, "end": 415 } ], "namedExports": [ { "start": 427, "end": 443, "names": { "myVar": {} } } ], "typeExports": [ { "start": 455, "end": 471, "names": { "T": {} } } ] } */
Debug
Known issues
gotchaThis package requires input code to be syntactically correct and well-formatted. It is not designed to validate or lint code with errors, but to parse valid module declarations.
fix
Ensure the source string passed to `parseImportsExports` is valid JavaScript/TypeScript, potentially pre-processed by a linter or formatter like Prettier.
affects: >=0.1.0
breakingAs the package is in an early `0.x.x` version series, its API (including the structure of the returned `ImportExportResult` object) is subject to non-backward-compatible changes in minor releases.
fix
Refer to the official GitHub repository for the latest API documentation and breaking change notes before upgrading. Consider pinning to exact minor versions to avoid unexpected changes.
affects: >=0.1.0
gotchaThe parser works specifically for `import` and `export` declarations and `require()` calls. It does not provide a full Abstract Syntax Tree (AST) for the entire file, nor does it handle all possible JavaScript/TypeScript syntax errors beyond its scope.
fix
Use a dedicated full AST parser (e.g., Acorn, Babel, TypeScript compiler API) if you require comprehensive code analysis or error detection beyond module declarations.
affects: >=0.1.0
Errors
Common errors & fixes
SyntaxError: Unexpected token
The input source string contains invalid JavaScript/TypeScript syntax or is poorly formatted, which causes the underlying parser to fail.
fix
Validate and format your source code using a tool like ESLint or Prettier before passing it to `parseImportsExports`. Ensure all import/export statements are syntactically correct.
TypeError: parseImportsExports is not a function
This typically occurs when trying to use CommonJS `require` to import the module or attempting to destructure a non-existent export, especially in an ESM-first project.
fix
Use `import { parseImportsExports } from 'parse-imports-exports';` in modern Node.js and browser environments that support ES modules. If using CommonJS, ensure your project setup correctly transpiles or resolves ESM imports.
Could not parse import/exports with acorn: $error
This error message indicates an issue with the underlying parser (Acorn, or similar) failing to interpret a specific import or export statement due to invalid syntax or an unexpected token.
fix
Review the specific import/export statement causing the error. Ensure it adheres strictly to ECMAScript/TypeScript syntax, including correct use of keywords, module specifiers, and proper termination.
Upgrade
Version history
0.2.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
4
Resources
parse-imports-exports — npm install parse-imports-exports · libregistry