Node.js runtime that can instantaneously load TypeScript & ESM, powered by esbuild.
- Transforms TypeScript & ESM → to CJS or ESM (depending on package type)
- Supports TS extensions
.cjs
&.mjs
(.cts
&.mts
) - Supports Node.js v12.20+
- Handles
node:
import prefixes - Hides experimental feature warnings
npm install --save-dev tsx
Install it globally to use it anywhere, outside of your npm project, without npx.
npm install --global tsx
Note: Commands are prefixed with
npx
to execute thetsx
binary, but it's not necessary if globally installed or when using it in thescript
object inpackage.json
npx tsx ./file.ts
Run file and automatically re-run on changes.
All imported files are watched except from the following directories:
node_modules
, bower_components
, vendor
, dist
, and .*
(hidden directories).
Press Return to manually re-run.
npx tsx watch ./file.ts
Modules transformations are cached in the system cache directory (TMPDIR
). Transforms are cached by content hash so duplicate dependencies are not re-transformed.
Set the --no-cache
flag to disable the cache:
npx tsx --no-cache ./file.ts
-
@esbuild-kit/esm-loader - Node.js Loader to transform TypeScript to ESM.
-
@esbuild-kit/cjs-loader - Node.js
requie()
hook to transform TypeScript & ESM to CommonJS.