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
- 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.
- 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.
- 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).
- TypeScript: types are bundled; install nothing extra.
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.
| Runtime | require("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.2Module 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).
| 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
Other esm-only packages
- ansi-styles 7.0.0last CJS
5.2.0 - strip-ansi 7.2.0last CJS
6.0.1 - commander 15.0.0last CJS
14.0.3 - supports-color 11.0.0last CJS
8.1.1 - chalk 6.0.0last CJS
4.1.2 - string-width 8.2.2last CJS
4.2.3 - ansi-regex 6.3.0last CJS
5.0.1 - escape-string-regexp 5.0.0last CJS
4.0.0
Similar popularity
- @jest/reporters 30.5.1Dual
- @smithy/hash-node 4.5.2CommonJS
- luxon 3.7.2Dual
- jest-runtime 30.5.1Dual
- @smithy/middleware-retry 4.8.2CommonJS
- import-local 3.2.0CommonJS
- bser 2.1.1CommonJS
- eslint-plugin-prettier 5.5.6CommonJS