or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

cli.mdconfiguration.mdcore-service.mdesm.mdindex.mdregister.mdrepl.mdtranspilers.md
tile.json

tessl/npm-ts-node

TypeScript execution environment and REPL for Node.js with source map support

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/ts-node@10.9.x

To install, run

npx @tessl/cli install tessl/npm-ts-node@10.9.0

index.mddocs/

ts-node

ts-node is a TypeScript execution environment and REPL for Node.js that enables direct execution of TypeScript files without precompilation. It works by JIT-transforming TypeScript into JavaScript using Node.js module loading APIs, making it seamlessly integrate with other Node.js tools and libraries.

Package Information

  • Package Name: ts-node
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install ts-node

Core Imports

import { register, create, Service, CreateOptions } from "ts-node";
import type * as _ts from "typescript";

For CommonJS:

const { register, create } = require("ts-node");

Basic Usage

import { register } from "ts-node";

// Register ts-node globally to handle .ts files
const service = register({
  transpileOnly: true,
  compilerOptions: {
    target: "es2020",
    module: "commonjs",
  },
});

// Now you can require/import .ts files directly
const myModule = require("./my-typescript-file.ts");

Architecture

ts-node is built around several key components:

  • Service Interface: Core compilation and registration system (Service, register, create)
  • Module Loaders: CommonJS and ESM integration hooks for transparent TypeScript execution
  • REPL Environment: Interactive TypeScript REPL with support for top-level await
  • CLI Tools: Command-line executables for various execution modes
  • Transpiler Integration: Support for alternative transpilers like SWC for faster compilation
  • Configuration System: Deep integration with TypeScript's tsconfig.json and compiler options

Capabilities

Core Service Management

Core functionality for creating and registering TypeScript compilation services. This is the primary API for programmatic usage.

function register(opts?: RegisterOptions): Service;
function register(service: Service): Service;
function create(rawOptions?: CreateOptions): Service;

interface Service {
  ts: TSCommon;
  config: _ts.ParsedCommandLine;
  options: RegisterOptions;
  enabled(enabled?: boolean): boolean;
  ignored(fileName: string): boolean;
  compile(code: string, fileName: string, lineOffset?: number): string;
  getTypeInfo(code: string, fileName: string, position: number): TypeInfo;
}

Core Service Management

Configuration Options

Comprehensive configuration system supporting all TypeScript compiler options plus ts-node specific features.

interface CreateOptions {
  cwd?: string;
  emit?: boolean;
  scope?: boolean;
  scopeDir?: string;
  pretty?: boolean;
  transpileOnly?: boolean;
  typeCheck?: boolean;
  compilerHost?: boolean;
  logError?: boolean;
  files?: boolean;
  compiler?: string;
  transpiler?: string | [string, object];
  swc?: boolean;
  ignore?: string[];
  project?: string;
  projectSearchDir?: string;
  skipProject?: boolean;
  skipIgnore?: boolean;
  compilerOptions?: object;
  ignoreDiagnostics?: Array<number | string>;
  require?: Array<string>;
  experimentalReplAwait?: boolean;
  moduleTypes?: ModuleTypes;
  esm?: boolean;
  preferTsExts?: boolean;
  experimentalSpecifierResolution?: 'node' | 'explicit';
  experimentalTsImportSpecifiers?: boolean;
}

Configuration Options

REPL Environment

Interactive TypeScript REPL with evaluation context management and experimental top-level await support.

function createRepl(options?: CreateReplOptions): ReplService;

interface ReplService {
  evalCode(code: string, context: object): any;
  start(): void;
  nodeEval(code: string, context: object, filename: string, callback: Function): void;
}

REPL Environment

ESM Integration

Native ECMAScript module support with loader hooks for seamless TypeScript execution in ESM contexts.

function createEsmHooks(tsNodeService: Service): EsmHooks;
function registerAndCreateEsmHooks(opts?: RegisterOptions): EsmHooks;

interface NodeLoaderHooksAPI2 {
  resolve(specifier: string, context: object, next: Function): Promise<object>;
  load(url: string, context: object, next: Function): Promise<object>;
}

ESM Integration

Register Entry Points

Convenient entry points for different registration modes, designed for use with Node.js --require flag.

// Available entry points:
// ts-node/register - Default registration
// ts-node/register/transpile-only - Fast transpile-only mode  
// ts-node/register/type-check - Explicit type checking mode
// ts-node/register/files - Include tsconfig files mode

Register Entry Points

CLI Integration

Command-line interfaces for executing TypeScript files and interactive REPL sessions.

// Available CLI binaries:
// ts-node - Main CLI with REPL support
// ts-node-cwd - CLI with working directory change
// ts-node-esm - CLI with native ESM support  
// ts-node-script - Script execution without REPL
// ts-node-transpile-only - Fast transpile-only CLI
// ts-script - Deprecated alias

CLI Integration

Transpiler Integration

Support for alternative transpilers like SWC for faster compilation and experimental features.

interface TranspilerModule {
  create(options: CreateTranspilerOptions): Transpiler;
}

interface Transpiler {
  transpile(code: string, options: TranspileOptions): TranspileOutput;
}

Transpiler Integration

Types

interface TypeInfo {
  name: string;
  comment: string;
}

interface RegisterOptions extends CreateOptions {
  experimentalResolver?: boolean;
}

type ModuleTypes = Record<string, ModuleTypeOverride>;
type ModuleTypeOverride = 'cjs' | 'esm' | 'package';
type ExperimentalSpecifierResolution = 'node' | 'explicit';

/** @deprecated Use Service instead */
type Register = Service;

/** @internal TypeScript configuration options interface */
interface TsConfigOptions extends Omit<RegisterOptions, 
  | 'transformers' 
  | 'readFile' 
  | 'fileExists' 
  | 'skipProject' 
  | 'project' 
  | 'dir' 
  | 'cwd' 
  | 'projectSearchDir' 
  | 'optionBasePaths' 
  | 'tsTrace'
> {}

/** @internal Diagnostic filter interface */
interface DiagnosticFilter {
  appliesToAllFiles: boolean;
  filenamesAbsolute: string[];
  diagnosticsIgnored: number[];
}

/** @internal Node.js module emit types */
type NodeModuleEmitKind = 'nodeesm' | 'nodecjs';

class TSError extends Error {
  name: 'TSError';
  diagnosticText: string;
  diagnostics: ReadonlyArray<_ts.Diagnostic>;
  diagnosticCodes: number[];
}

/** TypeScript compiler interface */
interface TSCommon {
  version: string;
  sys: _ts.System;
  ScriptTarget: typeof _ts.ScriptTarget;
  ModuleKind: typeof _ts.ModuleKind;
  JsxEmit: typeof _ts.JsxEmit;
  createProgram: typeof _ts.createProgram;
  transpileModule: typeof _ts.transpileModule;
  getDefaultLibFileName: typeof _ts.getDefaultLibFileName;
  // ... other TypeScript compiler APIs
}

Constants

const VERSION: string;
const REGISTER_INSTANCE: symbol;
const DEFAULTS: RegisterOptions;

/** @internal Debug logging function */
const debug: (...args: any[]) => void;

/** @internal Typed process.env interface */
const env: ProcessEnv;

/** @internal Custom inspect symbol */
const INSPECT_CUSTOM: string | symbol;