JSPM

  • Created
  • Published
  • Downloads 9676342
  • Score
    100M100P100Q232081F
  • License MIT

Node.js runtime enhanced with esbuild for loading TypeScript & ESM

Package Exports

  • tsx/repl

Readme

tsx

Node.js enhanced with esbuild to run TypeScript & ESM

Features

  • Transforms TypeScript & ESM → to CJS or ESM (depending on package type)
  • Supports TS extensions .cjs & .mjs (.cts & .mts)
  • TypeScript REPL
  • Supports Node.js v12.20+
  • Handles node: import prefixes
  • Hides experimental feature warnings

Install

npm install --save-dev tsx

Install globally

Install it globally to use it anywhere, outside of your npm project, without npx.

npm install --global tsx

Usage

Note: Commands are prefixed with npx to execute the tsx binary, but it's not necessary if globally installed or when using it in the script object in package.json

Run TypeScript / ESM / CJS module

Pass in a file to run:

npx tsx ./file.ts

Watch mode

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

REPL

Start a TypeScript REPL by running tsx with no arguments.

npx tsx

Cache

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

Dependencies

FAQ

Does it do type-checking?

No, esbuild does not support type checking.

It's recommended to run TypeScript separately as a command (tsc --noEmit) or via IDE IntelliSense.

How is tsx different from ts-node?

They are both tools to run TypeScript files and start a TypeScript REPL.

The main difference is that tsx is powered by esbuild for blazing fast compilation. But because it uses esbuild, it doesn't type check like ts-node.

If you migrated from ts-node, please share your performance gains here!