我的问题是,当我调试节点应用程序时,仅通过运行debug就看不到承诺的结果。
例如,我有以下无法调试的代码:
sampleRepository
.find()
.then(result => result) // breakpoint goes here
.catch(err => err)
当我在其中放置断点时,看不到结果变量的值。因此,我必须重构代码以解决该问题。我正在做的工作是:
sampleRepository
.find()
.then(result => {
return result; // breakpoint goes here
})
.catch(err => err)
有效,因为现在我可以看到“结果”变量的值,但是我必须每次都重构代码。有没有更简单的方法来调试这些Promise而不是重构代码?
实际上vscode
已经支持此功能。可以在then
处理程序上设置断点,然后在击中断点后使用step into。检查我制作的这个小.gif文件:https://ibb.co/YLNmzZ3