What it is
tsx runs TypeScript files directly with no build step, using esbuild for near-instant transpilation. It is the modern replacement for ts-node.
Run or watch TypeScript entry points directly. tsx strips types without checking them, so pair it with tsc --noEmit for verification.
Installation
npm install -D tsxGetting started
The smallest useful thing you can do with it, and what each part means.
bash
# Run a script once
npx tsx scripts/seed.ts
# Restart on change during development
npx tsx watch src/server.ts
# In package.json
{
"scripts": {
"dev": "tsx watch src/server.ts",
"typecheck": "tsc --noEmit"
}
}Advanced usage
Where the library earns its place over a simpler alternative.
json
// tsx honours the paths in tsconfig.json automatically
{
"compilerOptions": {
"baseUrl": ".",
"paths": { "@/*": ["src/*"] },
"module": "ESNext",
"moduleResolution": "bundler"
}
}
// Both of these work without extra flags:
import { config } from '@/config';
const { readFile } = require('node:fs/promises');Errors and fixes
The failures you are most likely to hit, and what actually resolves them.
- Type errors do not appear
- By design. Run tsc --noEmit separately; tsx only strips types.
- Cannot find module '@/thing'
- The path alias is missing from tsconfig, or baseUrl is not set. tsx reads them from there.
Best practices
- Always run tsc --noEmit in CI — tsx does not typecheck.
- Use tsx watch in development instead of nodemon plus a compile step.
- For production, compile ahead of time or use a bundler; tsx is a development tool.
- Prefer tsx over ts-node for new projects unless you specifically need ts-node's type checking.
Background
Why it exists, and what it was reacting to.
ts-node was slow and its ESM support was a persistent source of frustration. tsx wraps esbuild instead, starting in milliseconds and handling both module systems without configuration.
