在NodeJS中使用promise时未运行Console.log

Console.log not being run when using promise in NodeJS

本文关键字:运行 Console log promise NodeJS      更新时间:2024-02-13

这让我抓狂。我有下面的代码,当我运行它时,我只有debug-1打印。如果我注释掉where声明,我将得到要打印的debug-1debug-2

        console.log( 'debug-1' )
        var where = {
            compound_id: study.compound_id,
            species: {
                "like": ( species + "*" )
            },
            study_start: {
                "<=": study.study_start
            },
            study_start: {
                ">=": threeYearsBeforeStudy
            }
        }
        console.log( 'debug-2' )

超级奇特。我有一个承诺,但我相信这不应该是一个问题。

添加代码

process.on('unhandledRejection', console.log.bind(console))

到依赖项之后的节点文件的顶部。这会让你知道哪里出了问题,你的承诺似乎在任何地方都没有处理的情况下遇到了错误。