A lightweight TypeScript runtime loader for Node.js using custom import hooks. Run TypeScript files directly without pre-compilation.
- Direct execution - Run
.tsfiles without building - tsconfig.json support - Automatically loads and applies your TypeScript configuration
- Path aliases - Full support for
pathsin tsconfig.json (exact matches and wildcards) - Fast resolution - Optimized with caching for alias paths and transpiled modules
- Zero configuration - Works out of the box with sensible defaults
- Module interop - Import CommonJS, ESM, JSON, and TypeScript files seamlessly
npm install @yucacodes/tsRun any TypeScript file directly:
yts your-script.tsUse as a loader with Node.js:
node --import @yucacodes/ts your-script.tsCreate a tsconfig.json in your project root:
{
"compilerOptions": {
"module": "ESNext",
"target": "ES2015",
"paths": {
"@models/*": ["./src/models/*"],
"@utils": ["./src/utils/index.ts"]
}
}
}The loader will automatically:
- Find and load
tsconfig.jsonfrom your working directory - Apply your compiler options
- Resolve path aliases
The package uses Node.js custom import hooks to:
- Intercept TypeScript file imports
- Transpile them using the TypeScript compiler
- Cache transpiled modules with mtime validation
- Resolve path aliases from tsconfig.json
- TypeScript transpilation (
.tsfiles) - Path alias resolution (exact and wildcard patterns)
- CommonJS and ESM module imports
- JSON imports
- Source maps for debugging
- Module format detection (CommonJS/ESM based on tsconfig)
The loader includes several optimizations:
- Caching - Transpiled modules are cached with modification time validation
- Lazy resolution - Path aliases are pre-processed for O(1) exact lookups
- Skip JS files - JavaScript files bypass TypeScript processing entirely
ISC