File: options.md

package info (click to toggle)
ts-node 10.9.2%2B~cs64.13.20-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,388 kB
  • sloc: javascript: 15,071; sh: 83; makefile: 15; xml: 9
file content (408 lines) | stat: -rw-r--r-- 7,858 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
---
title: Options
---

All command-line flags support both `--camelCase` and `--hyphen-case`.

Most options can be declared in your tsconfig.json: [Configuration via tsconfig.json](./configuration.md#via-tsconfigjson-recommended)

`ts-node` supports `--print` (`-p`), `--eval` (`-e`), `--require` (`-r`) and `--interactive` (`-i`) similar to the [node.js CLI](https://nodejs.org/api/cli.html).

`ts-node` supports `--project` and `--showConfig` similar to the [tsc CLI](https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options).

_Environment variables, where available, are in `ALL_CAPS`_

## CLI Options

### help

```shell
ts-node --help
```

Prints the help text

### version

```shell
ts-node -v
ts-node -vvv
```

Prints the version. `-vv` includes node and typescript compiler versions.  `-vvv` includes absolute paths to ts-node and
typescript installations.

### eval

```shell
ts-node -e <typescript code>
# Example
ts-node -e 'console.log("Hello world!")'
```

Evaluate code

### print

```shell
ts-node -p -e <typescript code>
# Example
ts-node -p -e '"Hello world!"'
```

Print result of `--eval`

### interactive

```shell
ts-node -i
```

Opens the REPL even if stdin does not appear to be a terminal

### esm

```shell
ts-node --esm
ts-node-esm
```

Bootstrap with the ESM loader, enabling full ESM support


## TSConfig Options

### project

```shell
ts-node -P <path/to/tsconfig>
ts-node --project <path/to/tsconfig>
```

Path to tsconfig file.

*Note the uppercase `-P`. This is different from `tsc`'s `-p/--project` option.*

*Environment:* `TS_NODE_PROJECT`

### skipProject

```shell
ts-node --skipProject
```

Skip project config resolution and loading

*Default:* `false` <br/>
*Environment:* `TS_NODE_SKIP_PROJECT`

### cwdMode

```shell
ts-node -c
ts-node --cwdMode
ts-node-cwd
```

Resolve config relative to the current directory instead of the directory of the entrypoint script

### compilerOptions

```shell
ts-node -O <json compilerOptions>
ts-node --compilerOptions <json compilerOptions>
```

JSON object to merge with compiler options

*Environment:* `TS_NODE_COMPILER_OPTIONS`

### showConfig

```shell
ts-node --showConfig
```

Print resolved `tsconfig.json`, including `ts-node` options, and exit

## Typechecking

### transpileOnly

```shell
ts-node -T
ts-node --transpileOnly
```

Use TypeScript's faster `transpileModule`

*Default:* `false`<br/>
*Environment:* `TS_NODE_TRANSPILE_ONLY`

### typeCheck

```shell
ts-node --typeCheck
```

Opposite of `--transpileOnly`

*Default:* `true`<br/>
*Environment:* `TS_NODE_TYPE_CHECK`

### compilerHost

```shell
ts-node -H
ts-node --compilerHost
```

Use TypeScript's compiler host API

*Default:* `false` <br/>
*Environment:* `TS_NODE_COMPILER_HOST`

### files

```shell
ts-node --files
```

Load `files`, `include` and `exclude` from `tsconfig.json` on startup.  This may
avoid certain typechecking failures.  See [Missing types](./troubleshooting.md#missing-types) for details.

*Default:* `false` <br/>
*Environment:* `TS_NODE_FILES`

### ignoreDiagnostics

```shell
ts-node -D <code,code>
ts-node --ignoreDiagnostics <code,code>
```

Ignore TypeScript warnings by diagnostic code

*Environment:* `TS_NODE_IGNORE_DIAGNOSTICS`


## Transpilation Options

### ignore

```shell
ts-node -I <regexp matching ignored files>
ts-node --ignore <regexp matching ignored files>
```

Override the path patterns to skip compilation

*Default:* `/node_modules/` <br/>
*Environment:* `TS_NODE_IGNORE`

### skipIgnore

```shell
ts-node --skipIgnore
```

Skip ignore checks

*Default:* `false` <br/>
*Environment:* `TS_NODE_SKIP_IGNORE`

### compiler

```shell
ts-node -C <name>
ts-node --compiler <name>
```

Specify a custom TypeScript compiler

*Default:* `typescript` <br/>
*Environment:* `TS_NODE_COMPILER`

### swc

```shell
ts-node --swc
```

Transpile with [swc](./swc.md).  Implies `--transpileOnly`

*Default:* `false`

### transpiler

```shell
ts-node --transpiler <name>
# Example
ts-node --transpiler ts-node/transpilers/swc
```

Use a third-party, non-typechecking transpiler

### preferTsExts

```shell
ts-node --preferTsExts
```

Re-order file extensions so that TypeScript imports are preferred

*Default:* `false` <br/>
*Environment:* `TS_NODE_PREFER_TS_EXTS`


## Diagnostic Options

### logError

```shell
ts-node --logError
```

Logs TypeScript errors to stderr instead of throwing exceptions

*Default:* `false` <br/>
*Environment:* `TS_NODE_LOG_ERROR`

### pretty

```shell
ts-node --pretty
```

Use pretty diagnostic formatter

*Default:* `false` <br/>
*Environment:* `TS_NODE_PRETTY`

### TS_NODE_DEBUG

```shell
TS_NODE_DEBUG=true ts-node
```

Enable debug logging

## Advanced Options

### require

```shell
ts-node -r <module name or path>
ts-node --require <module name or path>
```

Require a node module before execution

### cwd

```shell
ts-node --cwd <path/to/directory>
```

Behave as if invoked in this working directory

*Default:* `process.cwd()`<br/>
*Environment:* `TS_NODE_CWD`

### emit

```shell
ts-node --emit
```

Emit output files into `.ts-node` directory. Requires `--compilerHost`

*Default:* `false` <br/>
*Environment:* `TS_NODE_EMIT`

### scope

```shell
ts-node --scope
```

Scope compiler to files within `scopeDir`.  Anything outside this directory is ignored.

*Default:* `false` <br/>
*Environment:* `TS_NODE_SCOPE`

### scopeDir

```shell
ts-node --scopeDir <path/to/directory>
```

Directory within which compiler is limited when `scope` is enabled.

*Default:* First of: `tsconfig.json` "rootDir" if specified, directory containing `tsconfig.json`, or cwd if no `tsconfig.json` is loaded.<br/>
*Environment:* `TS_NODE_SCOPE_DIR`

### moduleTypes

Override the module type of certain files, ignoring the `package.json` `"type"` field.  See [Module type overrides](./module-type-overrides.md) for details.

*Default:* obeys `package.json` `"type"` and `tsconfig.json` `"module"` <br/>
*Can only be specified via `tsconfig.json` or API.*

### TS_NODE_HISTORY

```shell
TS_NODE_HISTORY=<path/to/history/file> ts-node
```

Path to history file for REPL

*Default:* `~/.ts_node_repl_history`

### noExperimentalReplAwait

```shell
ts-node --noExperimentalReplAwait
```

Disable top-level await in REPL.  Equivalent to node's [`--no-experimental-repl-await`](https://nodejs.org/api/cli.html#cli_no_experimental_repl_await)

*Default:* Enabled if TypeScript version is 3.8 or higher and target is ES2018 or higher.<br/>
*Environment:* `TS_NODE_EXPERIMENTAL_REPL_AWAIT` set `false` to disable

### experimentalResolver

Enable experimental hooks that re-map imports and require calls to support:

* remapping extensions, e.g. so that `import "./foo.js"` will execute `foo.ts`. Currently the following extensions will be mapped:
  * `.js` to `.ts`, `.tsx`, or `.jsx`
  * `.cjs` to `.cts`
  * `.mjs` to `.mts`
  * `.jsx` to `.tsx`
* including file extensions in CommonJS, for consistency with ESM where this is often mandatory

In the future, this hook will also support:

* `baseUrl`, `paths`
* `rootDirs`
* `outDir` to `rootDir` mappings for composite projects and monorepos

For details, see [#1514](https://github.com/TypeStrong/ts-node/issues/1514).

*Default:* `false`, but will likely be enabled by default in a future version<br/>
*Can only be specified via `tsconfig.json` or API.*

### experimentalSpecifierResolution

```shell
ts-node --experimentalSpecifierResolution node
```

Like node's [`--experimental-specifier-resolution`](https://nodejs.org/dist/latest-v18.x/docs/api/esm.html#customizing-esm-specifier-resolution-algorithm), but can also be set in your `tsconfig.json` for convenience.
Requires [`esm`](#esm) to be enabled.

*Default:* `explicit`<br/>

## API Options

The API includes [additional options](https://typestrong.org/ts-node/api/interfaces/RegisterOptions.html) not shown here.