Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,18 @@ Most options can be specified by a `"ts-node"` object in `tsconfig.json` using t

Our bundled [JSON schema](https://unpkg.com/browse/ts-node@8.8.2/tsconfig.schema.json) lists all compatible options.

## SyntaxError
## Help! I'm getting a `SyntaxError` in `ts-node`, but my code compiles with `tsc`!

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.
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.

For example, if you're using the `?.` optional chaining operator with `"target": "esnext"` or `"target": "es2020"`, `tsc` won't transpile it,
and Node 12, which doesn't support `?.`, will throw a `SyntaxError`. If you lower `"target"` to `"es2019"`, `tsc` will transpile the `?.`
into a form that works on Node 12.

To determine which target to use, see https://github.com/microsoft/TypeScript/wiki/Node-Target-Mapping.

Any error that is not a `TSError` is thrown while running the transpiled code in Node.js after compilation succeeds.
If you see a `SyntaxError` or a `TypeError` from a builtin API being undefined, then you definitely need to lower your `target`.

### Import Statements

Expand Down