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. JSON
Dual (CommonJS + ESM) Dual package — both require() and import work
cjs-module-lexer publishes both a CommonJS entry and a native ESM entry (ESM added in 0.3.0). require("cjs-module-lexer") and import "cjs-module-lexer" both work on every supported Node.js version and in Bun.
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 | ✓ works | ✓ works |
How to import cjs-module-lexer
ES modules (import)
import cjsModuleLexer from "cjs-module-lexer";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 (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") and import "cjs-module-lexer" both work on every supported Node.js version and in Bun.
Can I require cjs-module-lexer?
Yes. cjs-module-lexer ships a CommonJS entry, so require("cjs-module-lexer") works on every Node.js version, alongside the native ESM entry for import.
Does cjs-module-lexer work in Bun?
Yes. import "cjs-module-lexer" loaded successfully in Bun 1.4 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
- glob 13.0.6Dual
- eslint-visitor-keys 5.0.1Dual
- yallist 5.0.0Dual
- balanced-match 4.0.4Dual
- js-yaml 5.4.1Dual
Similar popularity
- define-data-property 1.1.4CommonJS
- path-parse 1.0.7CommonJS
- domhandler 6.0.1ESM-only
- source-map-support 0.5.21CommonJS
- dom-serializer 3.1.1ESM-only
- jsonfile 6.2.1CommonJS
- fast-uri 4.1.4CommonJS
- indent-string 5.0.0ESM-only