Skip to content

Installation ​

Install tsx in a project for a shared, repeatable setup, or globally for commands used across directories. These are alternatives; a project installation does not need a global one.

You need Node.js and a package manager on your PATH. See compatibility for supported versions. For a first runnable example, follow Getting started.

Project installation ​

For development scripts, install tsx as a development dependency. This records the dependency in package.json so other contributors can install it too.

If you are starting in an empty directory, create package.json first with your package manager's initialization command, such as npm init -y or pnpm init.

Run one of these commands in the directory containing your project's package.json, using your project's package manager:

sh
npm install -D tsx
sh
pnpm add -D tsx
sh
yarn add -D tsx

Using tsx ​

In your project directory, add this file:

script.ts

ts
console.log('Hello from tsx!')

Run the installed executable through your package manager:

sh
npx tsx ./script.ts

It prints:

text
Hello from tsx!

Using it in package.json#scripts ​

To give the command a name, add a start entry to the scripts object in package.json. Keep any other fields and scripts your project already has.

Package scripts can reference the locally installed tsx directly:

package.json (merge this entry into your existing scripts)

json
{
    "scripts": {
        "start": "tsx ./script.ts"
    }
}

Run the script with your package manager:

sh
npm run start
sh
pnpm run start
sh
yarn run start

The package manager may print a command header, followed by the script output:

text
Hello from tsx!

Global installation ​

Global installation makes the tsx executable available across directories. It does not record tsx as a project dependency.

sh
npm install -g tsx
sh
pnpm add -g tsx

Yarn 2 and later do not support global installation. Use project installation, or see Yarn's guidance on yarn dlx for running a package without adding it to a project.

With the global package manager's executable directory on your PATH, you can call tsx directly. From the directory containing script.ts, run:

sh
tsx ./script.ts

It prints:

text
Hello from tsx!

Troubleshooting ​

  • tsx: command not found: use npx tsx inside a project installation, or check that your global package manager's executable directory is on PATH.
  • An install prompt when using npx: the package is not installed in the current project. Install dependencies and run the command from that project's directory.
  • Missing tsx after deployment: development dependencies may have been omitted. If your application executes through tsx in production, declare it as a runtime dependency; see deployment choices.