parse-imports is a high-performance JavaScript utility for parsing ES module imports within a given string of code. It leverages the `es-module-lexer` (a WASM-based library) for its core parsing logic, ensuring speed and accuracy. The library is currently at version 3.0.0 and actively maintained, with major versions often introducing updated Node.js runtime requirements. Key features include identifying various module specifier types (e.g., package, relative, absolute, builtin), correctly unescaping specifier sequences, collecting default, named, and namespace imports, and handling dynamic `import()` expressions. It also provides functionality to resolve module specifier paths using `require.resolve`. This makes it a robust tool for static analysis, bundlers, and development tools that need to understand module dependencies.
npm install parse-importsVerified import paths — ran on the pinned version, not inferred.
Demonstrates parsing ES module imports from a code string, showing both asynchronous iteration and conversion to an array of import objects, highlighting different import types.
Upgrade your Node.js runtime to version 22 or later.
Upgrade your Node.js runtime to version 18 or later, or downgrade `parse-imports` to v1.x.
Update your import statements to use named imports: `import { parseImports } from 'parse-imports'`.For CommonJS files, use dynamic `import()` (e.g., `const { parseImports } = await import('parse-imports');`) or convert your consuming module to ES Modules.Use ES module import syntax: `import { parseImports } from 'parse-imports'`.Use named import syntax: `import { parseImports } from 'parse-imports'`.Convert your consuming file to an ES Module (e.g., change `.js` to `.mjs` or add `"type": "module"` to `package.json`), or use dynamic `import()` within CJS: `const { parseImports } = await import('parse-imports');`.Upgrade your Node.js runtime to version 22 or higher. Alternatively, downgrade `parse-imports` to a version compatible with your current Node.js environment (e.g., v2.x for Node.js >=18 <22, v1.x for Node.js <18).