我期待 Bluebird forgotten return warning出现,但由于某种原因它不起作用。
A demo :
const Bluebird = require('bluebird');
Bluebird.config({
warnings: true
})
Bluebird.resolve(1)
.then(() => {
Bluebird.resolve(2); // should warn about forgotten return
})
.then(two => console.log(two));
如何解决输出警告?
我怀疑我以前遇到过这个问题,但我不记得解决方案是什么。
最佳答案
似乎需要启用长堆栈跟踪才能显示警告。您可以使用配置对象来启用它们 ( docs ) ( demo ):
Bluebird.config({
warnings: true,
longStackTraces: true
});
In Node.js you may configure warnings and long stack traces for the entire process using environment variables:
BLUEBIRD_LONG_STACK_TRACES=1 BLUEBIRD_WARNINGS=1 node app.js
Both features are automatically enabled if the BLUEBIRD_DEBUG environment variable has been set or if the NODE_ENV environment variable is equal to "development".
和
To enable long stack traces and warnings in node development:
$ NODE_ENV=development node server.js
To enable long stack traces and warnings in node production:
$ BLUEBIRD_DEBUG=1 node server.js
编辑为什么这是必要的:
似乎默认情况下警告和长堆栈跟踪都是禁用的,并且仅在检测到开发环境时才启用,请参阅 here :
Note that even though false is the default here, a development environment might be detected which automatically enables long stack traces and warnings.
关于javascript - Bluebird 忘记返回警告丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54266477/