node-tsx
Run Node.js with TypeScript and JSX syntax support in .ts, .tsx, and .jsx files.
node-tsx transforms supported source files before Node.js executes them, including TypeScript syntax that requires JavaScript code generation such as enums, runtime namespaces, and parameter properties. JSX compiler options are read from the nearest tsconfig.json for each loaded file.
The loader does not type check, change Node.js module resolution, apply TypeScript path aliases, or downlevel JavaScript syntax for older runtimes.
Installation
npm i remix
Usage
Pass the --import flag to register the remix/node-tsx loader when executing node:
node --import remix/node-tsx ./server.ts
TypeScript configuration
Since import resolution still follows Node.js, configure type checking to match native Node loading:
{
"compilerOptions": {
"module": "NodeNext",
"moduleResolution": "NodeNext",
"allowImportingTsExtensions": true,
"isolatedModules": true,
"verbatimModuleSyntax": true,
"rewriteRelativeImportExtensions": true
}
}
Do not enable erasableSyntaxOnly if you want TypeScript to accept the same transform-only syntax that node-tsx can execute.
Programmatic usage
Registering the loader
Import remix/node-tsx as a side effect to register the loader.
import 'remix/node-tsx'
Loading a module with scoped JSX support
Load a module with TypeScript and JSX syntax support scoped to its import graph:
import { loadModule } from 'remix/node-tsx/load-module'
let mod = await loadModule('./app/server.tsx', import.meta.url)
Related Work
License
See LICENSE