tsx
A drop-in replacement for the node CLI that runs TypeScript and ESM files instantly, powered by esbuild.
Repository Health
Technical Analysis
tsx (TypeScript Execute) is a Node.js enhancement that lets you run TypeScript files the same way you’d run a plain JavaScript file with node — no build step, no ts-node configuration, no separate loader setup. Under the hood it swaps in esbuild to transform TypeScript and modern JavaScript syntax on the fly, then re-spawns node with the appropriate CommonJS or ESM hooks wired in via —require/—import.
Beyond straight execution, tsx smooths over the CJS/ESM split that has fragmented the Node.js ecosystem since ES Modules landed: it lets CommonJS code require() ESM dependencies without hitting ERR_REQUIRE_ESM, resolves tsconfig.json path aliases at runtime, and honors Node’s own CLI flags so it behaves exactly like node in every other respect. A built-in watch mode reruns your script on file changes for fast iteration, and a Developer API (tsImport, register hooks, an entry-point import) lets other tools and libraries load TypeScript files programmatically without tsx owning the whole process.
What You Get
- A
tsxCLI that behaves exactly likenode— same flags, same argument positioning — but accepts .ts/.tsx/.mts/.cts files directly - Automatic CJS/ESM interop so CommonJS code can require() ESM-only packages without ERR_REQUIRE_ESM
- esbuild-powered on-the-fly transforms with a filesystem cache so repeat runs skip re-compilation
- tsconfig.json path-alias resolution baked into both the CJS resolver and the ESM loader hook
- Built-in watch mode (
tsx watch) that restarts your script on file changes, with include/exclude globs and screen clearing - A TypeScript-aware REPL and a patched Node test runner integration (
tsx --test) for .ts test files - A Developer API (register, tsImport, entry-point import) for embedding TypeScript loading into other tools without invoking the tsx CLI
Common Use Cases
- Running one-off TypeScript scripts or CLI tools during local development without a compile step
- Powering the
dev/startscript for Node.js backends written in TypeScript, in place of ts-node - Loading TypeScript configuration files (e.g. build tool configs) from within another program via the tsImport API
- Executing TypeScript test files directly with Node’s built-in test runner via
tsx --test - Iterating on scripts with
tsx watchso file saves automatically re-run the process
Under The Hood
Architecture
tsx separates a thin CLI entry point (src/cli.ts) from the actual execution mechanism (src/run.ts), which re-spawns a child node process with --require flags for a preflight script and a REPL patch, plus --import/--loader pointing at a loader that wires in the CJS and ESM hooks. Those hooks live in clearly separated src/cjs and src/esm/hook directories that plug into Node’s own module-resolution APIs rather than monkey-patching internals. Watch mode (src/watch) reuses the same spawn-based run() function behind a file watcher, relaying OS signals between parent and child over an IPC socket — so the spawn/hook wiring in run.ts is a shared foundation that watch mode, the REPL, and the Developer API entry points all depend on.
Tech Stack Written in TypeScript targeting es2022 with strict compiler settings, and transformed by esbuild both for its own build (via pkgroll) and as its runtime execution engine. Uses cleye for CLI flag parsing, chokidar for watch-mode file watching, get-tsconfig for tsconfig path-alias resolution, cross-spawn to launch the child node process, and kolorist for terminal output styling. Ships dual CJS/ESM builds through a detailed package.json exports map — there’s no database or web framework involved, since this is a Node.js runtime-augmentation tool distributed purely through npm.
Code Quality An extensive test suite under tests/specs covers CLI behavior, watch mode, the REPL, module loaders, tsconfig resolution, CJS/ESM interop contracts, and even PTY-based shell interaction, run through the manten test runner across multiple Node.js versions with a CI timeout guard to catch stuck runs. Strict TypeScript settings (strict mode, noImplicitOverride) are paired with lintroll for linting, and the codebase consistently separates CJS and ESM concerns into distinct source directories rather than mixing them.
What Makes It Unique
tsx treats CommonJS/ESM interop as a first-class problem rather than an afterthought — resolving package.json exports subpaths, letting require() tolerate ESM-only dependencies, and doing so through Node’s official loader hook APIs instead of patching internals directly. That’s a meaningful point of differentiation from older TypeScript-execution tools that predate stable loader hooks, though the core idea of transforming TypeScript through esbuild at require/import time is a pattern this project shares with several comparable tools.
Used by 177 apps in this directory
Pezzo
AI Development · Monitoring
Open-source LLMOps platform for prompt management, AI observability, intelligent caching, and real-time cost tracking across LLM providers.
Arize Phoenix
Analytics · Devops · Monitoring
Open-source AI observability platform for tracing, evaluating, and debugging LLM applications with built-in intelligence and MCP support.
Pi
AI Agents
An open-source, self-extensible agent harness and coding agent CLI — a modular runtime (agent core, unified multi-provider LLM API, TUI) with no built-in permission system by default, documented containerization patterns for sandboxing instead.
Plane
Collaboration · Productivity · Project Management
Open-source project management platform to replace Jira, Linear, and ClickUp — with built-in cycles, real-time collaborative docs, and full self-hosting.
Plasmic
CMS · Design Tools · Low Code Platforms
The open-source visual builder that lets teams design React apps and websites with drag-and-drop while integrating seamlessly with your codebase.
Polar
Developer Tools · Ecommerce · Invoicing Finance
Open source payments infrastructure that turns software into a business — subscriptions, usage-based billing, digital products, and merchant-of-record compliance in one platform.
PostHog
Ab Testing Experimentation · Analytics · Developer Tools
The all-in-one open source product platform combining analytics, session replay, feature flags, error tracking, AI observability, and a built-in data warehouse in a single self-hostable stack.
Prime Agent
AI Agents · AI Code Assistants · Developer Tools
An open-source coding and research agent built around a Recursive Language Model that treats context as variables and a persistent Python REPL as its only tool.
Promptfoo
AI Development
An open-source CLI and library for evaluating and red-teaming LLM applications — replace trial-and-error prompt engineering with systematic evals, vulnerability scanning, and CI/CD integration.