canirequire › Dual (CommonJS + ESM) › cjs-module-lexer
Is cjs-module-lexer ESM-only? Can you require() it?
Lexes CommonJS modules, returning their named exports metadata
Last verified Sep 9, 2026 against cjs-module-lexer@2.2.1. Markdown · JSON
Dual (CommonJS + ESM) Dual package — require() works on every Node.js version we test; import works too
cjs-module-lexer publishes both a CommonJS entry and a native ESM entry (ESM added in 0.3.0). require("cjs-module-lexer") works on every Node.js version we test (18, 20, 22, 24 and 26) and in Bun. import "cjs-module-lexer" works alongside it.
What to do
- Nothing to change. require("cjs-module-lexer") works on every Node.js version we test (18, 20, 22, 24 and 26) and in Bun. import * as cjsModuleLexer from "cjs-module-lexer" works alongside it; use named imports for what the ESM entry exports.
- TypeScript: types are bundled; install nothing extra.
Does cjs-module-lexer@2.2.1 actually load? Runtime test results
Installed and executed on Sep 9, 2026 with require("cjs-module-lexer") from a CommonJS file and import "cjs-module-lexer" from an ES module.
| Runtime | require("cjs-module-lexer") | import "cjs-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 cjs-module-lexer
ES modules (import)
import * as cjsModuleLexer from "cjs-module-lexer";Namespace import shown because the ESM entry may have no default export; use named imports for what it exports.
CommonJS (require)
const cjsModuleLexer = require("cjs-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 (48 versions; the newest 48 shown).
| Versions | Format | First published |
|---|---|---|
| 0.3.0 – 2.2.1 | Dual (CommonJS + ESM) | Sep 25, 2020 |
| 0.1.0 – 0.2.12 | CommonJS | May 14, 2020 |
Frequently asked
Is cjs-module-lexer ESM-only?
cjs-module-lexer@2.2.1 ships CommonJS and ESM builds. cjs-module-lexer publishes both a CommonJS entry and a native ESM entry (ESM added in 0.3.0). require("cjs-module-lexer") works on every Node.js version we test (18, 20, 22, 24 and 26) and in Bun. import "cjs-module-lexer" works alongside it.
Can I require cjs-module-lexer?
Yes. cjs-module-lexer ships a CommonJS entry alongside the native ESM entry. require("cjs-module-lexer") works on every Node.js version we test (18, 20, 22, 24 and 26) and in Bun.
Does cjs-module-lexer work in Bun?
Yes. import "cjs-module-lexer" loaded successfully in Bun 1.4.0 on Sep 9, 2026.
Does cjs-module-lexer ship TypeScript types?
Yes. cjs-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
- define-data-property 1.1.4CommonJS
- path-parse 1.0.7CommonJS
- domhandler 6.0.1ESM-only
- source-map-support 0.5.21CommonJS
- @opentelemetry/semantic-conventions 1.43.0CommonJS
- @humanfs/node 0.16.8ESM-only
- dom-serializer 3.1.1ESM-only
- jsonfile 6.2.1CommonJS