tsc-watch
raw JSON →tsc-watch is a utility that wraps the TypeScript compiler's --watch mode and adds lifecycle hooks to execute commands on compilation events such as success, failure, or first success. It is commonly used as a drop-in replacement for nodemon in TypeScript projects to restart a Node.js server after successful recompilations. The current stable version is 7.2.0, with a release cadence of several minor versions per year. Key differentiators include built-in support for debounced file emission events, signal handling, and the ability to run arbitrary commands without needing an additional process manager. Unlike plain tsc --watch, tsc-watch provides fine-grained control over development workflows and integrates seamlessly with TypeScript's existing compiler options.
Common errors
error Error: Cannot find module 'tsc-watch/client' ↓
error tsc-watch: command not found ↓
error TypeError: tscWatchClient is not a constructor ↓
Warnings
breaking Version 6.0.0 dropped CommonJS support; programmatic API is ESM-only. Requiring 'tsc-watch' with require() will fail. ↓
deprecated The --compiler option is deprecated and will be removed in a future version. ↓
gotcha onSuccess command is killed with SIGTERM on process exit; if your command spawns child processes, they may not be cleaned up. ↓
gotcha The --onEmit event fires for each emitted file, so a single compilation may trigger multiple commands. This can cause race conditions if commands are not idempotent. ↓
gotcha tsc-watch requires a peer dependency of TypeScript; using a mismatched TypeScript version may cause unexpected behavior. ↓
Install
npm install tsc-watch yarn add tsc-watch pnpm add tsc-watch Imports
- tsc-watch (CLI) wrong
tsc --watch --onSuccess "node dist/index.js"correctnpx tsc-watch --onSuccess "node dist/index.js" - default (programmatic API) wrong
const TscWatchClient = require('tsc-watch').defaultcorrectimport TscWatchClient from 'tsc-watch/client' - TscWatchClient (type import) wrong
import { TscWatchClient } from 'tsc-watch'correctimport type TscWatchClient from 'tsc-watch/client'
Quickstart
npx tsc-watch --onSuccess "node dist/index.js" --noClear