canirequire

canirequire › ESM-only › through2

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

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

Last verified Sep 9, 2026 against through2@5.0.11. Markdown · JSON

ESM-only ESM-only since 5.0.0 — last CommonJS version is 4.0.2

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

Does through2@5.0.11 actually load? Runtime test results

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

Runtimerequire("through2")import "through2"
Node.js 18✗ failsERR_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 (import)

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 (require)

// 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, corrected where a runtime test of that version contradicted them (50 versions; the newest 50 shown).

VersionsFormatFirst published
5.0.0 – 5.0.11ESM-onlyMay 7, 2026
0.0.0 – 4.0.2CommonJSAug 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

Other esm-only packages

Similar popularity