ts-node uses sensible default configurations to reduce boilerplate while still respecting
tsconfig.json if you
have one. If you are unsure which configuration is used, you can log it with
ts-node --show-config. This is similar to
tsc --showConfig but includes
"ts-node" options as well.
ts-node also respects your locally-installed
typescript version, but global installations fallback to the globally-installed
typescript. If you are unsure which versions are used,
ts-node -vv will log them.
It is important to differentiate between errors from
ts-node, errors from the TypeScript compiler, and errors from
node. It is also important to understand when errors are caused by a type error in your code, a bug in your code, or a flaw in your configuration.
Type errors from the compiler are thrown as a
TSError. These are the same as errors you get from
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 bugs in your code or configuration.
Your version of
"target" option. Otherwise your code will compile fine, but node will throw a
node 12 does not understand the
?. optional chaining operator. If you use
"target": "esnext", then the following TypeScript syntax:
When you try to run this code, node 12 will throw a
SyntaxError. To fix this, you must switch to
"target": "es2019" or lower so TypeScript transforms
?. into something
node can understand.