canirequire › Dual (CommonJS + ESM) › es-module-lexer
Is es-module-lexer ESM-only? Can you require() it?
Lexes ES modules returning their import/export metadata
Last verified Sep 9, 2026 against es-module-lexer@3.0.2. Markdown · JSON
Dual (CommonJS + ESM) Dual package — require() works on every Node.js version we test; import works too
es-module-lexer publishes both a CommonJS entry and a native ESM entry (ESM added in 0.1.2). require("es-module-lexer") works on every Node.js version we test (18, 20, 22, 24 and 26) and in Bun. import "es-module-lexer" works alongside it.
What to do
- Nothing to change. require("es-module-lexer") works on every Node.js version we test (18, 20, 22, 24 and 26) and in Bun. import * as esModuleLexer from "es-module-lexer" works alongside it; use named imports for what the ESM entry exports.
- TypeScript: types are bundled; install nothing extra.
Does es-module-lexer@3.0.2 actually load? Runtime test results
Installed and executed on Sep 9, 2026 with require("es-module-lexer") from a CommonJS file and import "es-module-lexer" from an ES module.
| Runtime | require("es-module-lexer") | import "es-module-lexer" |
|---|---|---|
| Node.js 18 | ✓ works | ✓ works |
| Node.js 20 | ✓ works | ✓ works |
| Node.js 22 | ✓ works | ✓ works |
| Node.js 24 | ✓ works | ✓ works |
| Node.js 26 | ✓ works | ✓ works |
| Bun 1.4.0 | ✓ works | ✓ works |
How to import es-module-lexer
ES modules (import)
import * as esModuleLexer from "es-module-lexer";Namespace import shown because the ESM entry may have no default export; use named imports for what it exports.
CommonJS (require)
const esModuleLexer = require("es-module-lexer");Module format by version
Derived from the type, main and exports fields of every stable release on npm, corrected where a runtime test of that version contradicted them (79 versions; the newest 60 shown).
| Versions | Format | First published |
|---|---|---|
| 0.7.0 – 3.0.2 | Dual (CommonJS + ESM) | Jul 5, 2021 |
| 0.3.17 – 0.6.0 | CommonJS | Feb 18, 2020 |
| 0.3.15 – 0.3.16 | Dual (CommonJS + ESM) | Feb 12, 2020 |
Frequently asked
Is es-module-lexer ESM-only?
es-module-lexer@3.0.2 ships CommonJS and ESM builds. es-module-lexer publishes both a CommonJS entry and a native ESM entry (ESM added in 0.1.2). require("es-module-lexer") works on every Node.js version we test (18, 20, 22, 24 and 26) and in Bun. import "es-module-lexer" works alongside it.
Can I require es-module-lexer?
Yes. es-module-lexer ships a CommonJS entry alongside the native ESM entry. require("es-module-lexer") works on every Node.js version we test (18, 20, 22, 24 and 26) and in Bun.
Does es-module-lexer work in Bun?
Yes. import "es-module-lexer" loaded successfully in Bun 1.4.0 on Sep 9, 2026.
Does es-module-lexer ship TypeScript types?
Yes. es-module-lexer bundles its own type declarations; no @types package is needed.
Links
Other dual (commonjs + esm) packages
- minimatch 10.2.6Dual
- brace-expansion 5.0.9Dual
- lru-cache 11.5.2Dual
- tslib 2.8.1Dual
- glob 13.0.6Dual
- eslint-visitor-keys 5.0.1Dual
- yallist 5.0.0Dual
- balanced-match 4.0.4Dual
Similar popularity
- lightningcss-linux-x64-gnu 1.33.0CommonJS
- strip-final-newline 4.0.0ESM-only
- prettier 3.9.6Dual
- @opentelemetry/api-logs 0.222.0CommonJS
- mkdirp 3.0.1Dual
- ansi-escapes 7.3.0ESM-only
- @nodelib/fs.stat 4.0.0CommonJS
- merge-descriptors 2.0.0CommonJS