Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface RegisterOptions

Options for registering a TypeScript compiler instance globally.

Hierarchy

Index

Properties

Optional compiler

compiler?: string

Specify a custom TypeScript compiler.

default

"typescript"

Optional compilerHost

compilerHost?: boolean

Use TypeScript's compiler host API instead of the language service API.

default

false

Optional compilerOptions

compilerOptions?: object

JSON object to merge with TypeScript compilerOptions.

Optional cwd

cwd?: string

Behave as if invoked within this working directory. Roughly equivalent to cd $dir && ts-node ...

default

process.cwd()

Optional dir

dir?: string

Legacy alias for cwd

deprecated

use projectSearchDir or cwd

Optional emit

emit?: boolean

Emit output files into .ts-node directory.

default

false

Optional esm

esm?: boolean

Enable native ESM support.

Optional experimentalReplAwait

experimentalReplAwait?: boolean

Allows the usage of top level await in REPL.

Uses node's implementation which accomplishes this with an AST syntax transformation.

Enabled by default when tsconfig target is es2018 or above. Set to false to disable.

Note: setting to true when tsconfig target is too low will throw an Error. Leave as undefined to get default, automatic behavior.

Optional experimentalResolver

experimentalResolver?: boolean

Enable experimental features that re-map imports and require calls to support: baseUrl, paths, rootDirs, .js to .ts file extension mappings, outDir to rootDir mappings for composite projects and monorepos.

Optional experimentalSpecifierResolution

experimentalSpecifierResolution?: "node" | "explicit"

Like node's --experimental-specifier-resolution, , but can also be set in your tsconfig.json for convenience.

Optional experimentalTsImportSpecifiers

experimentalTsImportSpecifiers?: boolean

Allow using voluntary .ts file extension in import specifiers.

Typically, in ESM projects, import specifiers must have an emit extension, .js, .cjs, or .mjs, and we automatically map to the corresponding .ts, .cts, or .mts source file. This is the recommended approach.

However, if you really want to use .ts in import specifiers, and are aware that this may break tooling, you can enable this flag.

Optional files

files?: boolean

Load "files" and "include" from tsconfig.json on startup.

Default is to override tsconfig.json "files" and "include" to only include the entrypoint script.

default

false

Optional ignore

ignore?: string[]

Paths which should not be compiled.

Each string in the array is converted to a regular expression via new RegExp() and tested against source paths prior to compilation.

Source paths are normalized to posix-style separators, relative to the directory containing tsconfig.json or to cwd if no tsconfig.json is loaded.

Default is to ignore all node_modules subdirectories.

default

["(?:^|/)node_modules/"]

Optional ignoreDiagnostics

ignoreDiagnostics?: (string | number)[]

Ignore TypeScript warnings by diagnostic code.

Optional logError

logError?: boolean

Logs TypeScript errors to stderr instead of throwing exceptions.

default

false

Optional moduleTypes

moduleTypes?: ModuleTypes

Override certain paths to be compiled and executed as CommonJS or ECMAScript modules. When overridden, the tsconfig "module" and package.json "type" fields are overridden, and the file extension is ignored. This is useful if you cannot use .mts, .cts, .mjs, or .cjs file extensions; it achieves the same effect.

Each key is a glob pattern following the same rules as tsconfig's "include" array. When multiple patterns match the same file, the last pattern takes precedence.

cjs overrides matches files to compile and execute as CommonJS. esm overrides matches files to compile and execute as native ECMAScript modules. package overrides either of the above to default behavior, which obeys package.json "type" and tsconfig.json "module" options.

Optional preferTsExts

preferTsExts?: boolean

Re-order file extensions so that TypeScript imports are preferred.

For example, when both index.js and index.ts exist, enabling this option causes require('./index') to resolve to index.ts instead of index.js

default

false

Optional pretty

pretty?: boolean

Use pretty diagnostic formatter.

default

false

Optional project

project?: string

Path to TypeScript config file or directory containing a tsconfig.json. Similar to the tsc --project flag: https://www.typescriptlang.org/docs/handbook/compiler-options.html

Optional projectSearchDir

projectSearchDir?: string

Search for TypeScript config file (tsconfig.json) in this or parent directories.

Optional require

require?: string[]

Modules to require, like node's --require flag.

If specified in tsconfig.json, the modules will be resolved relative to the tsconfig.json file.

If specified programmatically, each input string should be pre-resolved to an absolute path for best results.

Optional scope

scope?: boolean

Scope compiler to files within scopeDir.

default

false

Optional scopeDir

scopeDir?: string
default

First of: tsconfig.json "rootDir" if specified, directory containing tsconfig.json, or cwd if no tsconfig.json is loaded.

Optional skipIgnore

skipIgnore?: boolean

Skip ignore check, so that compilation will be attempted for all files with matching extensions.

default

false

Optional skipProject

skipProject?: boolean

Skip project config resolution and loading.

default

false

Optional swc

swc?: boolean

Transpile with swc instead of the TypeScript compiler, and skip typechecking.

Equivalent to setting both transpileOnly: true and transpiler: 'ts-node/transpilers/swc'

For complete instructions: https://typestrong.org/ts-node/docs/transpilers

Optional transformers

transformers?: CustomTransformers | ((p: Program) => CustomTransformers)

Optional transpileOnly

transpileOnly?: boolean

Use TypeScript's faster transpileModule.

default

false

Optional transpiler

transpiler?: string | [string, object]

Specify a custom transpiler for use with transpileOnly

Optional typeCheck

typeCheck?: boolean

DEPRECATED Specify type-check is enabled (e.g. transpileOnly == false).

default

true

Methods

Optional fileExists

  • fileExists(path: string): boolean

Optional readFile

  • readFile(path: string): undefined | string

Optional tsTrace

  • tsTrace(str: string): void
  • A function to collect trace messages from the TypeScript compiler, for example when traceResolution is enabled.

    default

    console.log

    Parameters

    • str: string

    Returns void

Generated using TypeDoc