You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+11-12Lines changed: 11 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -221,9 +221,18 @@ Most options can be specified by a `"ts-node"` object in `tsconfig.json` using t
221
221
222
222
Our bundled [JSON schema](https://unpkg.com/browse/ts-node@8.8.2/tsconfig.schema.json) lists all compatible options.
223
223
224
-
## SyntaxError
224
+
## Help! I'm getting a `SyntaxError` in `ts-node`, but my code compiles with `tsc`!
225
225
226
-
Any error that is not a `TSError` is from node.js (e.g. `SyntaxError`), and cannot be fixed by TypeScript or `ts-node`. These are runtime issues with your code.
226
+
This happens when your `compileOptions.target` is too high, so TypeScript leaves some fancy new syntax as-is, instead of transpiling it into a form your version of Node understands.
227
+
228
+
For example, if you're using the `?.` optional chaining operator with `"target": "esnext"` or `"target": "es2020"`, `tsc` won't transpile it,
229
+
and Node 12, which doesn't support `?.`, will throw a `SyntaxError`. If you lower `"target"` to `"es2019"`, `tsc` will transpile the `?.`
230
+
into a form that works on Node 12.
231
+
232
+
To determine which target to use, see https://github.com/microsoft/TypeScript/wiki/Node-Target-Mapping.
233
+
234
+
Any error that is not a `TSError` is thrown while running the transpiled code in Node.js after compilation succeeds.
235
+
If you see a `SyntaxError` or a `TypeError` from a builtin API being undefined, then you definitely need to lower your `target`.
227
236
228
237
### Import Statements
229
238
@@ -289,16 +298,6 @@ import UntypedJsLib from "untyped_js_lib"
289
298
290
299
**Tip:** If you _must_ use `files`, `include`, or `exclude`, enable `--files` flags or set `TS_NODE_FILES=true`.
291
300
292
-
## Help! I'm getting syntax errors in `ts-node`, but not in `tsc`!
293
-
294
-
This is probably because the `compilerOptions.target` in your `tsconfig.json` is a higher version of ECMAScript than your current version of Node supports.
295
-
296
-
For example, if you're using the `?.` optional chaining operator, and you have `"target": "esnext"` or `"target": "es2020"`, the `?.` won't get transpiled at all,
297
-
so if you're using Node 12, you'll get a syntax error because it doesn't natively support `?.`. If you lower `"target"` to `"es2019"`, it will transpile the `?.`
298
-
into a form that can run on Node 12.
299
-
300
-
To determine which target to use, see https://github.com/microsoft/TypeScript/wiki/Node-Target-Mapping.
301
-
302
301
## Watching and Restarting
303
302
304
303
**TypeScript Node** compiles source code via `require()`, watching files and code reloads are out of scope for the project. If you want to restart the `ts-node` process on file change, existing node.js tools such as [nodemon](https://github.com/remy/nodemon), [onchange](https://github.com/Qard/onchange) and [node-dev](https://github.com/fgnass/node-dev) work.
0 commit comments