[英]Why is ts-node not compiling typescript file?
Why is ts-node not compiling and executing typescript file?为什么 ts-node 不编译和执行打字稿文件? It is used in terminal like "ts-node scriptfile" It just returns a blank line.
它在像“ts-node scriptfile”这样的终端中使用它只是返回一个空行。 What is wrong?
怎么了? Thanks for the help.
谢谢您的帮助。
There is another simple way of running .ts files 还有另一种运行.ts文件的简单方法
First of all you have to install typescript 首先你要安装打字稿
npm i -g typescript
then run your .ts file with this command 然后使用此命令运行.ts文件
tsc fileName.ts | node fileName.js
Note: the command above will generate an extra file named fileName.js 注意:上面的命令将生成一个名为fileName.js的额外文件
and finally make sure that you are using console.log() to return anything 最后确保您使用console.log()返回任何内容
ts-node
is a typescript executor, not a compiler. ts-node
是一个打字稿执行器,而不是一个编译器。 If you run npx ts-node script.ts
it will execute as typescript, without compiling.如果您运行
npx ts-node script.ts
它将作为打字稿执行,而无需编译。
To generate a compiled js file, try tsc script.ts
.要生成已编译的 js 文件,请尝试
tsc script.ts
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.