{"id":26515,"library":"ts-watch","title":"ts-watch","description":"ts-watch is a wrapper around the TypeScript compiler (tsc) that adds a --onSuccess COMMAND argument to run a command after every successful compilation. It is a fork of tsc-watch with fixes for macOS compatibility. Version 6.2.0 is the latest stable release, with periodic updates. Unlike raw tsc --watch, it provides lifecycle hooks (onSuccess, onFirstSuccess, onFailure, onCompilationComplete) to restart servers or run tests. It uses the locally installed TypeScript compiler and does not modify compilation behavior.","status":"active","version":"1.0.8","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/gilamran/tsc-watch","tags":["javascript","TypeScript"],"install":[{"cmd":"npm install ts-watch","lang":"bash","label":"npm"},{"cmd":"yarn add ts-watch","lang":"bash","label":"yarn"},{"cmd":"pnpm add ts-watch","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"ts-watch runs the currently installed TypeScript compiler; it requires tsc to be available in node_modules/.bin","package":"typescript","optional":false}],"imports":[{"note":"ts-watch is a CLI tool, not a library. Use it via npm scripts or npx. There is no programmatic API.","wrong":"require('ts-watch')","symbol":"ts-watch (CLI)","correct":"npx ts-watch"},{"note":"The --onSuccess command runs after a successful compilation. It is terminated before the next run.","wrong":"","symbol":"run onSuccess","correct":"ts-watch --onSuccess \"node dist/index.js\""},{"note":"Available since v3.0. Runs only on the first successful compilation after watch starts.","wrong":"","symbol":"run onFirstSuccess","correct":"ts-watch --onFirstSuccess \"echo first success\""},{"note":"Available since v4.0. Runs when compilation fails.","wrong":"","symbol":"run onFailure","correct":"ts-watch --onFailure \"echo compilation failed\""}],"quickstart":{"code":"npm install --save-dev ts-watch typescript\nmkdir src\ncat > src/index.ts << 'EOF'\nconst greeting: string = \"Hello, world!\";\nconsole.log(greeting);\nEOF\ncat > tsconfig.json << 'EOF'\n{\n  \"compilerOptions\": {\n    \"outDir\": \"./dist\",\n    \"strict\": true\n  },\n  \"include\": [\"src\"]\n}\nEOF\n# Run ts-watch with onSuccess to execute the compiled file\nnpx ts-watch --project tsconfig.json --onSuccess \"node dist/index.js\"","lang":"typescript","description":"Installs ts-watch, sets up a basic TypeScript project with a simple file, and demonstrates running ts-watch to watch for changes and execute the output on success."},"warnings":[{"fix":"If previously using tsc-watch, uninstall it: npm uninstall tsc-watch and install ts-watch: npm install --save-dev ts-watch. Then change all references in scripts from 'tsc-watch' to 'ts-watch'.","message":"ts-watch is a fork of tsc-watch. Migration: replace 'tsc-watch' with 'ts-watch' in package.json scripts and update imports.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Ensure TypeScript is installed: npm install --save-dev typescript","message":"ts-watch requires TypeScript to be installed. If using global tsc, the local project must also have TypeScript as a devDependency.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure your server process can be gracefully terminated. Use a process manager like 'wait-on' or 'concurrently' if needed.","message":"The --onSuccess command is terminated before a new compilation starts. Long-running processes (e.g., servers) may not restart properly if they don't handle SIGTERM.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Upgrade to latest: npm install --save-dev ts-watch@latest","message":"Very old versions (1.x) may not support --onFirstSuccess or --onFailure. Upgrade to v6+.","severity":"deprecated","affected_versions":"<3.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use npx ts-watch or add a script in package.json: \"scripts\": { \"watch\": \"ts-watch ...\" } then run npm run watch.","cause":"ts-watch is not installed or not in PATH when running directly.","error":"sh: ts-watch: command not found"},{"fix":"Upgrade to ts-watch@>=6.0.5: npm install --save-dev ts-watch@latest","cause":"ts-watch passes --watch to tsc, which conflicts with --build. Fixed in v6.0.5.","error":"error TS6369: Option '--build' must be the first command line argument"},{"fix":"Use ts-watch as a CLI tool, not a library. Remove require('ts-watch') and use the command line.","cause":"Using ts-watch programmatically via require('ts-watch') which does not export anything.","error":"TypeError: Cannot read property 'onSuccess' of undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}