Registry / web-framework / ts-babel

ts-babel

JSON →
library6.1.7jsnpmunverified

ts-babel (v6.1.7) transforms the output of the TypeScript compiler using Babel for fine-grained control over target environments. It acts as a bridge between TypeScript's compilation and Babel's polyfill and syntax transformation capabilities, allowing projects to use TypeScript for type checking and modern syntax while leveraging Babel for cross-browser compatibility. Key differentiator: avoids duplicate parsing by feeding TypeScript's emit directly into Babel, preserving source maps. Maintenance status unknown (last release likely older). Requires TypeScript ^3.5.2 as a peer dependency and Node >=8.10.0.

npm install ts-babel
INSTALL
IMPORT
SIG · TS-BABEL
T
ts-babel
web-frameworkjavascriptv6.1.7
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

tsBabel
import tsBabel from 'ts-babel'
const tsBabel = require('ts-babel').default
Default export is a function. In CommonJS, use require('ts-babel').default or set esModuleInterop.
transform
import { transform } from 'ts-babel'
const { transform } = require('ts-babel')
Named export is available but less commonly used; default export is recommended for single-file compilation.
TransformOptions
import type { TransformOptions } from 'ts-babel'
import { TransformOptions } from 'ts-babel'
TypeScript type export, use import type for type-only imports to avoid runtime errors.

This shows how to compile a TypeScript file with ts-babel: takes TS code, compiles with TypeScript, then transforms with Babel preset-env for browser compatibility.

import tsBabel from 'ts-babel'; import * as fs from 'fs'; const code = fs.readFileSync('example.ts', 'utf8'); tsBabel({ code, filename: 'example.ts', typescript: true, babel: { presets: [ ['@babel/preset-env', { targets: '> 0.25%, not dead' }] ] } }).then(result => { console.log(result.code); }).catch(err => { console.error(err); });
Debug
Known issues
breakingPeer dependency TypeScript ^3.5.2 may cause issues with newer TypeScript versions (4.x+).
fix
Use a version of ts-babel that supports TypeScript >=4.0 or switch to a different tool (e.g., @babel/preset-typescript).
affects: >=6.1.7
deprecatedts-babel is not actively maintained; consider using @babel/preset-typescript with Babel directly.
fix
Migrate to @babel/preset-typescript and drop ts-babel dependency.
affects: >=0.0.0
gotchaWhen using CommonJS, the default export is not available via require directly; must use .default.
fix
Use require('ts-babel').default or enable esModuleInterop in tsconfig.
affects: >=6.0.0
gotchaThe transform function returns a promise; forgetting to await or handle errors may lead to silent failures.
fix
Always use .then() or await when calling tsBabel() or transform().
affects: >=6.0.0
Errors
Common errors & fixes
Error: Cannot find module 'typescript'
Missing peer dependency TypeScript, or not installed in the project.
fix
npm install typescript@^3.5.2
TypeError: tsBabel is not a function
Using require('ts-babel') without .default due to CommonJS module system.
fix
Use require('ts-babel').default or import tsBabel from 'ts-babel'.
Error: Cannot find module '@babel/core'
Missing @babel/core which is a runtime dependency of ts-babel.
fix
npm install @babel/core
Upgrade
Version history
6.1.7latest on npm
Audit
Dependencies
typescriptrequiredpeer dependency required to compile TypeScript before Babel transformation
@babel/corerequiredruntime dependency for Babel transformation of TypeScript output
Agent activity
9 hits · last 30 days
node
8
OpenAI (training)
1
Resources
ts-babel — npm install ts-babel · libregistry