canirequire › ESM-only › tslib
Is tslib ESM-only? Can you require() it?
Runtime library for TypeScript helper functions
Last verified Sep 9, 2026 against tslib@2.8.1. JSON
ESM-only ESM-only since 2.5.3 — last CommonJS version is 2.5.2
tslib dropped its CommonJS build in 2.5.3 (June 2023). The last version you can require() on every Node.js version, including 18 and older, is 2.5.2, published May 18, 2023.
On Node.js 20.19+, 22.12+ and every newer release, require("tslib") works anyway: Node can load synchronous ES modules through require(). Verified on Node 20, 22, 24, 26. Node.js 18 and older still fail with ERR_REQUIRE_ESM.
Does tslib@2.8.1 actually load? Runtime test results
Installed and executed on Sep 9, 2026 with require("tslib") from a CommonJS file and import "tslib" from an ES module.
| Runtime | require("tslib") | import "tslib" |
|---|---|---|
| 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 | ✓ works | ✓ works |
How to import tslib
ES modules (import)
import tslib from "tslib";CommonJS (require)
// Node.js 20.19+ / 22.12+ / newer (package has no top-level await):
const tslib = require("tslib");
// Any Node.js version:
const tslib = await import("tslib");
// Or pin the last CommonJS release:
// npm install tslib@2.5.2Module format by version
Derived from the type, main and exports fields of every stable release on npm (45 versions; the newest 45 shown).
| Versions | Format | First published |
|---|---|---|
| 2.5.3 – 2.8.1 | ESM-only | Jun 2, 2023 |
| 2.0.2 – 2.5.2 | Dual (CommonJS + ESM) | Oct 6, 2020 |
| 2.0.0 – 2.0.1 | CommonJS | May 13, 2020 |
| 1.14.0 – 1.14.1 | Dual (CommonJS + ESM) | Oct 6, 2020 |
| 1.0.0 – 1.13.0 | CommonJS | Jun 28, 2016 |
Frequently asked
Is tslib ESM-only?
tslib@2.8.1 is ESM-only. tslib dropped its CommonJS build in 2.5.3 (June 2023). The last version you can require() on every Node.js version, including 18 and older, is 2.5.2, published May 18, 2023.
Which version of tslib still supports CommonJS / require()?
2.5.2 is the last version of tslib with a CommonJS build. Install it with "npm install tslib@2.5.2". Every version from 2.5.3 on is ESM-only.
How do I use tslib from a CommonJS file?
Use a dynamic import: const mod = await import("tslib"). On Node.js 20.19+, 22.12+ and newer, a plain require("tslib") also works for ESM packages that do not use top-level await. Alternatively pin tslib@2.5.2.
Does tslib work in Bun?
Yes. import "tslib" loaded successfully in Bun 1.4 on Sep 9, 2026.
Does tslib ship TypeScript types?
Yes. tslib 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
- supports-color 11.0.0ESM-only
- chalk 6.0.0ESM-only
- picomatch 4.0.7CommonJS
- lru-cache 11.5.2Dual
- glob 13.0.6Dual
- string-width 8.2.2ESM-only
- ansi-regex 6.3.0ESM-only
- eslint-visitor-keys 5.0.1Dual