What's the difference between tsc (TypeScript compiler) and ts-node?
15,151
Solution 1
The main difference is that tsc transpile all the file according to your tsconfig. Instead, ts-node will start from the entry file and transpile the file step by step through the tree based on the import/export
Solution 2
Most common practice is that tsc
is used for production build and ts-node
for development purposes running in --watch
mode along with nodemon
. This is a command i often use for development mode for my node/typescript projects:
"dev": "nodemon -w *.ts -e ts -x ts-node --files -H -T ./src/index.ts"
Related videos on Youtube
Author by
gremo
Updated on June 04, 2022Comments
-
gremo almost 2 years
I'm very confused about the difference between
tsc
andts-node
. I'm learning TypeScript and I usually transpile server.ts
files withtsc
command.Now, I'm approaching nestjs framework, and I see that it uses
ts-node
.So what's the difference between the two? Which one should I use?
-
gremo almost 6 years@jfriend00 can you elaborate your answer? AFAIK tsc will change
import
to the commonjsrequire()
, which in turn will load the JavaScript source file (assuming in node_modules). -
jfriend00 almost 6 yearsRead the first paragraph here: npmjs.com/package/ts-node
-
Michael Freidgeim over 4 yearsSome discussion at reddit.com/r/typescript/comments/8vkvzy/…
-
-
Krimson over 5 yearsSo which one to use and when?
-
Adrien De Peretti over 5 yearsIts a better practice to use tsc to build your project and then run it with node in production, its also faster
-
TetraDev over 3 yearsSometimes you only need to compile one entrypoint and it's imports -
ts-node
is perfect for that and has no downsides. -
Jeremy about 2 yearsi think that there is a ts-node-dev package which speeds build times up if performance is an issue
-
sotn about 2 years
tsc --watch
could've also been used which uses incremental builds and is faster thannodemon
.. -
Es Noguera about 2 yearsI'm wondering which builder should I use to build react applications nowadays
-
Molten Ice about 2 yearsQuick update on this, ts-node CAN be used in production: stackoverflow.com/questions/60581617/… and there's a faster way than using nodemon: npmjs.com/package/ts-node-dev