# Is through2 ESM-only? Can you require() it?

> through2@5.0.11 is ESM-only. ESM-only since 5.0.0 — last CommonJS version is 4.0.2.

Tiny utilities for inserting transformation logic into Node.js stream and Web Streams pipelines

Last verified Sep 9, 2026 against through2@5.0.11.

through2 dropped its CommonJS build in 5.0.0 (May 2026). The last version with a plain require()-able CommonJS entry is 4.0.2, published Jun 30, 2020.

On Node.js 20.19+, 22.12+ and newer, require("through2") works with the latest version: Node.js loads synchronous ES modules through require(). Verified on Node.js 20, 22, 24 and 26. On Node.js 18, which has no require(esm), require("through2") fails with ERR_REQUIRE_ESM.

## What to do

1. On Node.js 20.19+, 22.12+ and newer, require("through2") works with the latest version: Node.js loads synchronous ES modules through require(). Verified on Node.js 20, 22, 24 and 26.
2. From a CommonJS file, use a dynamic import inside an async function: const through2 = await import("through2"). That works on every Node.js version the package supports.
3. If you need a synchronous require() or run Node.js 18: npm install through2@4.0.2, the last CommonJS release (published Jun 30, 2020).
4. TypeScript: types are bundled; install nothing extra.

## Facts

- Latest: 5.0.11 (Jul 30, 2026)
- Module format: ESM-only
- Last CommonJS version: 4.0.2
- ESM-only since: 5.0.0 (May 7, 2026)
- TypeScript types: bundled
- Node engines: not declared
- Weekly downloads: 34.1M
- License: MIT

## Runtime test results for through2@5.0.11

Installed and executed on Sep 9, 2026 with require("through2") from a CommonJS file and import "through2" from an ES module.

| Runtime | require("through2") | import "through2" |
|---|---|---|
| Node.js 18 | fails (ERR_REQUIRE_ESM) | 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 through2

ES modules:

```js
import * as through2 from "through2";
```

Namespace import shown because the ESM entry may have no default export; use named imports for what it exports.

CommonJS:

```js
// Node.js 20.19+, 22.12+ and newer (verified):
const through2 = require("through2");

// Any Node.js version the package supports, from an async function:
async function main() {
  const through2 = await import("through2");
}

// Or pin the last CommonJS release:
// npm install through2@4.0.2
```

## Module format by version

Derived from the type, main and exports fields of every stable release on npm (50 versions; the newest 50 shown).

| Versions | Format | First published |
|---|---|---|
| 5.0.0 – 5.0.11 | ESM-only | May 7, 2026 |
| 0.0.0 – 4.0.2 | CommonJS | Aug 1, 2013 |

## Frequently asked

**Is through2 ESM-only?**

through2@5.0.11 is ESM-only. through2 dropped its CommonJS build in 5.0.0 (May 2026). The last version with a plain require()-able CommonJS entry is 4.0.2, published Jun 30, 2020.

**Which version of through2 still supports CommonJS / require()?**

4.0.2 is the last version of through2 with a CommonJS build. Install it with "npm install through2@4.0.2". Every version from 5.0.0 on is ESM-only.

**How do I use through2 from a CommonJS file?**

From a CommonJS file, use a dynamic import inside an async function: const through2 = await import("through2"). That works on every Node.js version the package supports. On Node.js 20.19+, 22.12+ and newer, require("through2") works with the latest version: Node.js loads synchronous ES modules through require(). Verified on Node.js 20, 22, 24 and 26. Alternatively pin through2@4.0.2.

**Does through2 work in Bun?**

Yes. import "through2" loaded successfully in Bun 1.4.0 on Sep 9, 2026.

**Does through2 ship TypeScript types?**

Yes. through2 bundles its own type declarations; no @types package is needed.

## Links

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