Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(README.md): add troubleshooting tip for syntax errors #1201

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions README.md
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