简体   繁体   English

ts-node 中未显示错误

[英]Errors not showing in ts-node

When I have an Error in my code, compiling with ts-node, the error does not appear in the console.当我的代码中出现错误时,使用 ts-node 编译时,控制台中不会出现错误。

For exemple: let data = await fs.readFileSync(path);例如: let data = await fs.readFileSync(path);

I have this code where I use "fs" to read a file, using a path that the function receive as parameter.我有这段代码,我使用“fs”读取文件,使用 function 作为参数接收的路径。 But when the path is from a file that does not exists nothing happends in the console.但是,当路径来自不存在的文件时,控制台中不会发生任何事情。 The only thing that happens is that the requisition never finish loading.唯一发生的事情是申请永远不会完成加载。

If I put a console.log like this in the code, the error appears saying that the file does not exists: console.log(fs.readFile(path, (data) => { }))如果我在代码中放置这样的console.log,则会出现错误,指出该文件不存在: console.log(fs.readFile(path, (data) => { }))

It doesn't make sense, since the errors are supposed to show in the console.这没有意义,因为错误应该显示在控制台中。 (This happens with lot of type of commum errors that make it harder to finish the application) (这发生在许多类型的通信错误中,这使得完成应用程序变得更加困难)

here's the repository with all the code https://github.com/Macintosh-1984/Pokedex_Express这是包含所有代码https://github.com/Macintosh-1984/Pokedex_Express的存储库

somebody help please请有人帮忙

You are not capture the error on readFile您没有捕获 readFile 上的错误

fs.readFile(path, 'utf8', function(err, data){
      // you have err here 
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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