A fast CommonJS module syntax lexer that detects named exports and reexports from CJS modules, used in Node.js core for ESM interop. Current stable version: 2.2.0. Maintained by Node.js team; release cadence is irregular but active for parser bugs and performance improvements. Key differentiators: extremely fast (~90ms/MB cold, ~15ms/MB warm), frozen detection patterns to ensure backwards compatibility across Node.js versions, and support for transpiler variations (e.g., TypeScript, Babel). Provides both Node.js (CJS) and Wasm (ESM) builds, with TypeScript declarations included.
npm install cjs-module-lexerNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates ESM usage with Wasm: import parse and init, await init(), parse a CJS source, and obtain exports/reexports arrays.
Add await init() before calling parse() in ESM environments. CJS users are unaffected.
Do not rely on detection of non-standard patterns. Ensure your code uses the documented export forms (e.g., exports.X = ..., module.exports = { ... }, Object.defineProperty(exports, ...)).Test your modules with the lexer to ensure expected exports are detected. For complex cases, consider alternative tools.
Filter out '__esModule' from exports if not needed: exports.filter(e => e !== '__esModule')
Upgrade to 2.2.0 or later, and verify export detection.
Add await init(); before any parse() call in ESM context.
Use const { parse } = require('cjs-module-lexer'); in CommonJS.Ensure source code is wrapped in a CommonJS module wrapper when lexing; the lexer expects valid CJS syntax.
Use require('./foo') with a string literal; ensure no dynamic expressions.No dependency data recorded yet.