我正在使用带有 gulp 的 Node 来运行一些构建任务。这一直很好,直到几天前。现在(我假设在升级/更新之后,不确定哪个具体。我相信这是 Node 从 14.4 到 14.5 的更新)我一直收到这个警告
[DEP0097] DeprecationWarning: Using a domain property in MakeCallback is deprecated. Use the async_context variant of MakeCallback or the AsyncResource class instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
我不知道如何使用 --trace-deprecation
用 gulp 所以我找不到触发它的原因。我实际的 gulpfile 更长,并且注释掉部分,更改
pipeline
至.pipe
,更新 Node 和依赖关系,使用 async/await
,而其他一些细微的变化并没有让我更接近缩小问题的范围。因此,我在下面设置了这个最小的工作示例:
clean_fake
) 不会触发警告 gulp clean
和 gulp styles
导致警告显示 const gulp = require('gulp');
const del = require('del');
const sass = require('gulp-sass');
async function clean() {
const deletedPaths = await del([ './js/*.site.js', './style.css' ], { dryRun: true });
console.log('Deleted files and directories:\n', deletedPaths.join('\n'));
}
async function clean_fake() {
const deletedPaths = await test();
console.log('Deleted files and directories:\n', deletedPaths.join('\n'));
}
function test() {
console.log('dummy function');
return [ 'test' ];
}
function styles() {
return gulp.src('./src/sass/style.scss').pipe(sass()).pipe(gulp.dest('./'));
}
exports.clean = clean;
exports.styles = styles;
exports.default = clean_fake;
当前版本:Node :v14.5.0
npm:6.14.6
删除:5.1.0
gulp :4.0.2
gulp 萨斯:4.1.0
PS:有这个类似的question ,但我的问题没有答案。
更新:
我想出了如何通过
NODE_OPTIONS
运行它来跟踪弃用。 :NODE_OPTIONS='--trace-deprecation' gulp
但是输出对我没有多大帮助(node:146806) [DEP0097] DeprecationWarning: Using a domain property in MakeCallback is deprecated. Use the async_context variant of MakeCallback or the AsyncResource class instead.
at emitMakeCallbackDeprecation (domain.js:123:13)
at FSReqCallback.topLevelDomainCallback (domain.js:134:5)
at FSReqCallback.callbackTrampoline (internal/async_hooks.js:121:14)
最佳答案
这是 known issue在 Node 14.5.0 中由 Gulp 依赖 async-done
引起使用已弃用的 domain
显示此警告的模块。
根据链接的 Gulp 问题中的一篇文章,在 Gulp 使用相关代码的上下文中,弃用错误不是故意的。
在 Node 14.6.0 中,不再为所有 Gulp 任务任务显示此警告(如果您的代码以不推荐的方式使用模块,您的自定义代码可能会触发警告)。
关于node.js - 运行 gulp 任务时如何解决 "Using a domain property in MakeCallback is deprecated"警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63011636/