canirequire

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

Latest
2.8.1 (Oct 31, 2024)
Module format
ESM-only
Last CommonJS version
2.5.2
ESM-only since
2.5.3 (Jun 2, 2023)
TypeScript types
Bundled
Node engines
not declared
Weekly downloads
374.4M
License
0BSD

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.

Runtimerequire("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.2

Module format by version

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

VersionsFormatFirst published
2.5.3 – 2.8.1ESM-onlyJun 2, 2023
2.0.2 – 2.5.2Dual (CommonJS + ESM)Oct 6, 2020
2.0.0 – 2.0.1CommonJSMay 13, 2020
1.14.0 – 1.14.1Dual (CommonJS + ESM)Oct 6, 2020
1.0.0 – 1.13.0CommonJSJun 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

Similar popularity