# Is cjs-module-lexer ESM-only? Can you require() it?

> cjs-module-lexer@2.2.1 ships CommonJS and ESM builds. Dual package — require() works on every Node.js version we test; import works too.

Lexes CommonJS modules, returning their named exports metadata

Last verified Sep 9, 2026 against cjs-module-lexer@2.2.1.

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

1. 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.
2. TypeScript: types are bundled; install nothing extra.

## Facts

- 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

## Runtime test results for cjs-module-lexer@2.2.1

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:

```js
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:

```js
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") 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

- [cjs-module-lexer on npm](https://www.npmjs.com/package/cjs-module-lexer)
- [Source repository](https://github.com/nodejs/cjs-module-lexer)
- [HTML version](https://canirequire.com/package/cjs-module-lexer/)
- [JSON version](https://canirequire.com/package/cjs-module-lexer.json)

---

For scripts and AI agents: any package is at https://canirequire.com/package/<name>/index.md (Markdown) or https://canirequire.com/package/<name>.json (JSON); the site index is https://canirequire.com/llms.txt. Fetch the URL directly; no search needed.
