Registry / devops / node-typescript-compiler

node-typescript-compiler

JSON →
library4.0.0jsnpmunverified

node-typescript-compiler is a Node.js module that exposes the functionality of the TypeScript compiler (tsc) by spawning the tsc command-line tool as a child process. This allows developers to programmatically invoke tsc from within a Node.js script, enabling advanced build workflows such as compiling multiple variants of modules (e.g., Node/browser) with different compiler options. The current stable version is 4.0.0. While a formal release cadence is not specified, a maintenance badge from 2023 indicates ongoing support. A key differentiator is its simple, reliable wrapper around the tsc CLI, which properly catches and reports compilation errors. It treats `typescript` itself as a peer dependency, giving users explicit control over which tsc version is used. This design promotes a clear separation of concerns, ensuring that node-typescript-compiler acts primarily as an orchestrator for the standard TypeScript toolchain.

npm install node-typescript-compiler
INSTALL
IMPORT
SIG · NODE-TYPESCRIPT-CO
N
node-typescript-compiler
devopsjavascriptv4.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
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 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

tsc
import tsc from 'node-typescript-compiler';
const tsc = require('node-typescript-compiler');
Since v4, this package is pure ESM, requiring Node.js >= 12. The default export is an object that contains the main `compile` function.
compile
import tsc from 'node-typescript-compiler'; await tsc.compile(...);
import { compile } from 'node-typescript-compiler';
The `compile` function is a method accessed via the default-exported `tsc` object, not a direct named export. Attempting to destructure it will fail.
CommonJS usage
const myCompiler = require('node-typescript-compiler');
CommonJS `require()` is not supported in version 4.0.0 and later. Ensure your project is configured for ESM or use an older major version (e.g., v3).

This quickstart compiles the current TypeScript project using the `tsconfig.json` located in the current directory.

import tsc from 'node-typescript-compiler'; async function compileProject() { try { console.log('Starting TypeScript compilation...'); await tsc.compile({ 'project': '.' // Refers to tsconfig.json in the current directory }); console.log('TypeScript compilation successful.'); } catch (error) { console.error('TypeScript compilation failed:', error.message); process.exit(1); } } compileProject();
Debug
Known issues
breakingVersion 4.0.0 and later of `node-typescript-compiler` are pure ESM (ECMAScript Modules) only. CommonJS `require()` is no longer supported.
fix
Update your project to use ESM `import` statements and ensure your Node.js environment is configured for ESM (e.g., by setting `"type": "module"` in `package.json`). Node.js version 12 or higher is required.
affects: >=4.0.0
breaking`node-typescript-compiler` now requires Node.js version 12 or higher due to its transition to pure ESM.
fix
Upgrade your Node.js runtime to version 12 or newer. For older Node.js versions, use `node-typescript-compiler@3`.
affects: >=4.0.0
gotchaThe `typescript` package is a peer dependency and must be installed separately as a sibling `devDependency`.
fix
Install `typescript` alongside `node-typescript-compiler`: `npm i --save-dev typescript node-typescript-compiler`.
affects: >=1.0.0
gotchaIt is strongly recommended to have a working TypeScript setup (with `tsc` and `tsconfig.json`) configured before using `node-typescript-compiler`.
fix
Verify your `tsconfig.json` and source files compile correctly by running `tsc --project .` directly in your terminal before integrating `node-typescript-compiler` into your build script.
affects: >=1.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module ... not supported.
Attempting to use CommonJS `require()` to import `node-typescript-compiler` v4.x.
fix
Migrate your project to ESM and use `import tsc from 'node-typescript-compiler';`, ensuring your `package.json` includes `"type": "module"` or files use `.mjs` extension. Alternatively, downgrade to `node-typescript-compiler@3` for CJS support.
Error: Command failed with exit code 1
The underlying `tsc` command invoked by `node-typescript-compiler` failed, likely due to compilation errors, a misconfigured `tsconfig.json`, or `tsc` not being found.
fix
Ensure the `typescript` package is installed (`npm i --save-dev typescript`). Check your `tsconfig.json` for errors, or verify your source files compile correctly by running `tsc --project .` directly. Enable verbose output in `node-typescript-compiler` options (`verbose: true`) for more detailed error messages from `tsc`.
TypeError: tsc.compile is not a function
The `node-typescript-compiler` module was not imported correctly, or the imported `tsc` object does not contain the `compile` method, possibly due to a version mismatch or incorrect import syntax.
fix
Verify you are using `import tsc from 'node-typescript-compiler';` and that the package is correctly installed in your `node_modules`.
Upgrade
Version history
4.0.0latest on npm
Audit
Dependencies
typescriptrequiredRequired as a sibling dev dependency for `tsc` functionality.
Agent activity
2 hits · last 30 days
node
2
Resources
node-typescript-compiler — npm install node-typescript-compiler · libregistry