Introduction
tsx makes running TypeScript on Node.js as simple as running JavaScript. It patches Node's module resolution to transpile TypeScript on the fly using esbuild, giving you sub-second startup times with zero configuration. It is designed as a modern, faster replacement for ts-node in everyday development workflows.
What tsx Does
- Runs TypeScript, JSX, and TSX files directly on Node.js without a build step
- Provides a watch mode that restarts on file changes via
tsx watch - Handles both ESM and CommonJS modules transparently
- Supports Node.js command-line flags like
--inspectfor debugging - Works as a drop-in replacement for
nodein scripts and npm scripts
Architecture Overview
tsx registers Node.js module hooks that intercept TypeScript file loads and pipe them through esbuild's transform API. Because esbuild is written in Go and runs natively, transpilation completes in single-digit milliseconds even for large files. tsx does not perform type checking, keeping the feedback loop fast. For ESM support, it uses Node's loader API to handle .ts and .tsx extensions natively.
Self-Hosting & Configuration
- Install with
npm install -D tsxas a dev dependency or globally withnpm install -g tsx - Use in npm scripts:
"dev": "tsx watch src/index.ts"for live-reloading development - Pass Node flags directly:
tsx --inspect src/server.tsfor debugger support - No tsconfig.json required for basic usage; esbuild handles modern TypeScript syntax automatically
- Use as a Node.js loader:
node --import tsx ./script.tsfor integration with other tooling
Key Features
- Near-instant startup thanks to esbuild's native Go transpiler
- Zero configuration needed for TypeScript, JSX, and path alias support
- Built-in watch mode with smart file change detection
- Supports the latest TypeScript and ECMAScript syntax features
- Small dependency footprint compared to full TypeScript compiler setups
Comparison with Similar Tools
- ts-node — more configurable with type checking support; tsx is faster for scripts that skip type checking
- Bun — built-in TypeScript support with its own runtime; tsx stays on standard Node.js
- esbuild-register — similar approach but tsx adds watch mode and better CLI ergonomics
- Deno — native TypeScript execution; tsx keeps compatibility with the npm ecosystem
- swc-node — SWC-based transpilation; tsx uses esbuild and provides a more complete CLI experience
FAQ
Q: Does tsx type-check my code?
A: No. tsx only transpiles. Run tsc --noEmit separately in CI or use your editor for type checking.
Q: Can I use tsx in production? A: tsx is optimized for development. For production, pre-compile with tsc or bundle with esbuild for optimal startup and smaller images.
Q: Does tsx support path aliases from tsconfig.json?
A: Yes. tsx reads paths from your tsconfig.json and resolves them automatically during module loading.
Q: How does watch mode work?
A: tsx watch monitors imported files for changes and restarts the process. It is faster than nodemon because it only watches files actually imported by your application.