canirequire

canirequireDual (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.

Latest
2.2.1 (Aug 13, 2026)
Module format
Dual (CommonJS + ESM)
Last CommonJS version
2.2.1
Native ESM since
0.3.0
TypeScript types
Bundled
Node engines
not declared
Weekly downloads
94.8M
License
MIT

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.

Runtimerequire("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).

VersionsFormatFirst published
0.3.0 – 2.2.1Dual (CommonJS + ESM)Sep 25, 2020
0.1.0 – 0.2.12CommonJSMay 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

Similar popularity