ts-babel

raw JSON →
6.1.7 verified Sat Apr 25 auth: no javascript maintenance

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.

error Error: Cannot find module 'typescript'
cause Missing peer dependency TypeScript, or not installed in the project.
fix
npm install typescript@^3.5.2
error TypeError: tsBabel is not a function
cause Using require('ts-babel') without .default due to CommonJS module system.
fix
Use require('ts-babel').default or import tsBabel from 'ts-babel'.
error Error: Cannot find module '@babel/core'
cause Missing @babel/core which is a runtime dependency of ts-babel.
fix
npm install @babel/core
breaking Peer 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).
deprecated ts-babel is not actively maintained; consider using @babel/preset-typescript with Babel directly.
fix Migrate to @babel/preset-typescript and drop ts-babel dependency.
gotcha When 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.
gotcha The 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().
npm install ts-babel
yarn add ts-babel
pnpm add ts-babel

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);
});