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

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

Lexes ES modules returning their import/export metadata

Last verified Sep 9, 2026 against es-module-lexer@3.0.2.

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

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

## Facts

- Latest: 3.0.2 (Sep 7, 2026)
- Module format: Dual (CommonJS + ESM)
- Last CommonJS version: 3.0.2
- Native ESM since: 0.1.2
- TypeScript types: bundled
- Node engines: not declared
- Weekly downloads: 113.9M
- License: MIT

## Runtime test results for es-module-lexer@3.0.2

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:

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

```js
const esModuleLexer = require("es-module-lexer");
```

## Module format by version

Derived from the type, main and exports fields of every stable release on npm (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

- [es-module-lexer on npm](https://www.npmjs.com/package/es-module-lexer)
- [Source repository](https://github.com/guybedford/es-module-lexer)
- [HTML version](https://canirequire.com/package/es-module-lexer/)
- [JSON version](https://canirequire.com/package/es-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.
