简体   繁体   中英

Why is ts-node not compiling typescript file?

Why is ts-node not compiling and executing typescript file? It is used in terminal like "ts-node scriptfile" It just returns a blank line. What is wrong? Thanks for the help.

There is another simple way of running .ts files

First of all you have to install typescript

npm i -g typescript

then run your .ts file with this command

tsc fileName.ts | node fileName.js

Note: the command above will generate an extra file named fileName.js

and finally make sure that you are using console.log() to return anything

ts-node is a typescript executor, not a compiler. If you run npx ts-node script.ts it will execute as typescript, without compiling.

To generate a compiled js file, try tsc script.ts .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM