Registry / web-framework / tslib
library1.8jsnpmunverified

tslib is a compact runtime library provided by Microsoft that contains all the essential helper functions emitted by the TypeScript compiler. It is primarily used in conjunction with the `--importHelpers` compiler option, which instructs TypeScript to import these common helper functions (such as `__extends`, `__assign`, `__decorate`, `__awaiter`) from `tslib` rather than embedding them directly in every compiled output file. This approach leads to significantly smaller JavaScript bundles and reduced runtime overhead by avoiding redundant function declarations. The current stable version is 2.8.1, with frequent patch and minor releases aligning with TypeScript's development. It differentiates itself by being the official, highly optimized runtime solution for TypeScript's emitted code, ensuring maximum compatibility and efficiency for projects compiled with TypeScript.

npm install tslib
INSTALL
IMPORT
SIG · TSLIB
T
tslib
web-frameworkjavascriptv1.8
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

__assign
✓ import { __assign } from 'tslib';
✗ const { __assign } = require('tslib');
While CommonJS destructuring is valid, the TypeScript compiler with `--importHelpers` typically emits `var tslib_1 = require("tslib"); exports.y = tslib_1.__assign({}, exports.x);`. Use named imports in ES Modules.
__awaiter
✓ import { __awaiter } from 'tslib';
✗ import __awaiter from 'tslib';
There is no default export for individual helpers. Always use named imports for specific tslib functions. This helper is crucial for downleveling `async/await`.
__decorate
✓ import { __decorate } from 'tslib';
✗ const decorate = require('tslib').__decorate;
Used when `emitDecoratorMetadata` is enabled. Ensure `tslib` is installed and resolved by your module system, especially in ES Module contexts where `require` is not available.
__importStar
✓ import { __importStar } from 'tslib';
✗ import * as tslib from 'tslib'; const myModule = tslib.__importStar(someObject);
This pattern is not strictly 'wrong' but less direct. The `__importStar` helper itself is used by TypeScript to implement `import * as name from 'module'` semantics for older module targets. Fixed to include non-enumerable keys in v2.8.1.

Configures TypeScript to automatically import helper functions from `tslib`, reducing code duplication and bundle size. Requires `npm install tslib`.

{ "compilerOptions": { "importHelpers": true, "target": "es2016", "module": "commonjs", "strict": true, "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true } }
Debug
Known issues
breakingOlder TypeScript versions require specific tslib versions. For TypeScript 3.8.4 or earlier, use `tslib@^1`. For TypeScript 2.3.2 or earlier, use `tslib@1.6.1`. Using a mismatch can lead to compilation errors or runtime issues where helpers are missing or incompatible.
fix
Check your `typescript` package version and install the compatible `tslib` version. For modern TypeScript (3.9.2+), `npm install tslib` typically installs the correct v2+.
affects: <2.0
gotchaProjects using `moduleResolution: 'node16'` or `'bundler'` in `tsconfig.json` require `tslib@^2.5.1` or later due to changes in `package.json` exports field. Older versions might not resolve correctly, leading to 'Cannot find module' errors.
fix
Upgrade to `tslib@^2.5.1` or later to ensure proper module resolution with modern TypeScript compiler settings and bundlers.
affects: <2.5.1
gotchaNew language features like `using` and `await using` declarations (introduced in TypeScript 5.2+) require `tslib@^2.6.0` or later. Using an older `tslib` with these features will result in runtime errors due to missing helper functions.
fix
Upgrade `tslib` to version 2.6.0 or higher to correctly support the runtime helpers for `using` and `await using` syntax emitted by the TypeScript compiler.
affects: <2.6.0
gotchaThe `__importStar` helper, used for `import * as name from 'module'`, did not correctly include non-enumerable keys from the imported module prior to v2.8.1. This could lead to missing properties at runtime for certain modules.
fix
Upgrade to `tslib@^2.8.1` to ensure `__importStar` accurately reflects the properties of imported modules, including non-enumerable ones.
affects: <2.8.1
deprecatedThe direct reference to `tslib.es6.js` from `package.json` exports was removed in `v2.5.3`. Projects relying on this specific path for ES6 output (e.g., custom bundler configurations) may experience broken imports.
fix
Rely on standard `package.json` `exports` or `module` fields for ES module resolution. Modern bundlers and TypeScript's `moduleResolution` settings should automatically resolve the correct entry point without direct path references.
affects: >=2.5.3
Errors
Common errors & fixes
Error: Cannot find module 'tslib' or its corresponding type declarations.
The `tslib` package is missing, or module resolution is failing to locate it when `importHelpers` is enabled in `tsconfig.json`.
fix
Run `npm install tslib` or `yarn add tslib`. Verify that `moduleResolution` in your `tsconfig.json` is correctly configured for your project (e.g., `node`, `node16`, `bundler`).
TypeError: tslib_1.__assign is not a function
TypeScript's emitted code expects `tslib` helpers to be available at runtime, but `tslib` either was not installed, was incorrectly installed, or a bundler failed to include or correctly process it in the final output.
fix
Ensure `tslib` is installed (`npm install tslib`) and that your build pipeline (e.g., webpack, Rollup, esbuild) is configured to include and correctly bundle `tslib`'s runtime helpers.
ReferenceError: __awaiter is not defined
This runtime error indicates that a `tslib` helper (such as `__awaiter` for `async/await`) is missing. This happens when `importHelpers` is enabled, but the `tslib` module is not loaded or its exports are inaccessible.
fix
Confirm `tslib` is a project dependency, is correctly installed, and that your module loader/bundler is successfully making the `tslib` helpers available at runtime. Ensure `tsconfig.json`'s `target` and `module` options are compatible with your runtime and `tslib` version.
Upgrade
Version history
1.8latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
38 hits · last 30 days
node
30
OpenAI (training)
1
Resources