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"
Share:
15,151

Related videos on Youtube

gremo
Author by

gremo

Updated on June 04, 2022

Comments

  • gremo
    gremo almost 2 years

    I'm very confused about the difference between tsc and ts-node. I'm learning TypeScript and I usually transpile server .ts files with tsc 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
      gremo almost 6 years
      @jfriend00 can you elaborate your answer? AFAIK tsc will change import to the commonjs require(), which in turn will load the JavaScript source file (assuming in node_modules).
    • jfriend00
      jfriend00 almost 6 years
      Read the first paragraph here: npmjs.com/package/ts-node
    • Michael Freidgeim
      Michael Freidgeim over 4 years
  • Krimson
    Krimson over 5 years
    So which one to use and when?
  • Adrien De Peretti
    Adrien De Peretti over 5 years
    Its a better practice to use tsc to build your project and then run it with node in production, its also faster
  • TetraDev
    TetraDev over 3 years
    Sometimes you only need to compile one entrypoint and it's imports - ts-node is perfect for that and has no downsides.
  • Jeremy
    Jeremy about 2 years
    i think that there is a ts-node-dev package which speeds build times up if performance is an issue
  • sotn
    sotn about 2 years
    tsc --watch could've also been used which uses incremental builds and is faster than nodemon..
  • Es Noguera
    Es Noguera about 2 years
    I'm wondering which builder should I use to build react applications nowadays
  • Molten Ice
    Molten Ice about 2 years
    Quick 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