typescript-compiler
raw JSON → 1.4.1-2 verified Sat Apr 25 auth: no javascript abandoned
A JavaScript library that wraps the TypeScript command-line compiler, providing programmatic API to compile TypeScript files and strings. The library exposes compile(), compileString(), and compileStrings() methods, allowing developers to integrate TypeScript compilation into Node.js workflows without shelling out to tsc. It supports passing compiler options, error callbacks, and can handle multiple source files with reference tags. Version 1.4.1-2 is the latest release, updated sporadically; no active development observed since 2016. Unlike ts-node or ts-jest, this wrapper is minimal and does not include a resolver, so all imports must be fully resolved.
Common errors
error Cannot find module 'typescript-compiler' ↓
cause npm install failed or package not in node_modules.
fix
Run 'npm install typescript-compiler' and ensure it is in your package.json.
error tsc.compile is not a function ↓
cause Incorrect import using ES6 import syntax.
fix
Use 'const tsc = require('typescript-compiler')' instead of 'import'.
error The 'options' parameter is deprecated and will be removed. ↓
cause Passing second argument as an options object to compile/compileString.
fix
Pass compiler arguments as a string array (e.g., ['--out', 'file.js']) instead of an object.
Warnings
deprecated The 'options' parameter is deprecated and will be removed in the next version. ↓
fix Use tscArgs string array instead of the options object.
gotcha Package bundles an outdated TypeScript compiler (likely 1.x). ↓
fix Install a separate TypeScript version and use the 'options' parameter to point to a different compiler? Not supported. Consider using ts-node or a modern wrapper.
gotcha Missing TypeScript dependency: The package does not list 'typescript' as a peer dependency. ↓
fix Ensure 'typescript' is installed separately if you want to use a different version.
breaking compileStrings() expects a Map/dictionary object, not an array. ↓
fix Pass an object with filenames as keys and source code as values.
Install
npm install typescript-compiler yarn add typescript-compiler pnpm add typescript-compiler Imports
- typescript-compiler wrong
import tsc from 'typescript-compiler'correctconst tsc = require('typescript-compiler') - compile wrong
tsc.compile('file.ts', { out: 'out.js' })correcttsc.compile(['file.ts'], ['--out', 'out.js']) - compileString wrong
var js = tsc.compileString('class A {}', { module: 'commonjs' })correctvar js = tsc.compileString('class A {}')
Quickstart
const tsc = require('typescript-compiler');
// Compile a TypeScript string
const result = tsc.compileString('let x: number = 1;', ['--noLib', '--target', 'ES5']);
console.log(result);