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.
Common errors
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
Warnings
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().
Install
npm install ts-babel yarn add ts-babel pnpm add ts-babel Imports
- tsBabel wrong
const tsBabel = require('ts-babel').defaultcorrectimport tsBabel from 'ts-babel' - transform wrong
const { transform } = require('ts-babel')correctimport { transform } from 'ts-babel' - TransformOptions wrong
import { TransformOptions } from 'ts-babel'correctimport type { TransformOptions } from 'ts-babel'
Quickstart
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);
});