【问题标题】:How to resolve "Using a domain property in MakeCallback is deprecated" warning when running gulp tasks?运行 gulp 任务时如何解决“不推荐使用 MakeCallback 中的域属性”警告?
【发布时间】:2020-07-21 09:39:10
【问题描述】:

我正在使用带有 gulp 的节点来运行一些构建任务。这一直很好,直到几天前。现在(我假设在升级/更新之后,不确定哪个具体。我相信这是节点从 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,更新节点和依赖项,使用async/await,以及其他一些小的更改并没有让我更接近缩小问题范围。

因此,我在下面设置了这个最小的工作示例:

  • 运行默认的 gulp 任务 (clean_fake) 不会触发警告
  • gulp cleangulp 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;

当前版本:
节点:v14.5.0
npm:6.14.6

删除:5.1.0
吞咽:4.0.2
gulp-sass: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)

【问题讨论】:

    标签: node.js gulp


    【解决方案1】:

    这是节点 14.5.0 中的 known issue 由 Gulp 依赖引起的 async-done 使用已弃用的 domain 模块,显示此警告。

    根据链接的 Gulp 问题中的帖子,在 Gulp 使用相关代码的上下文中,弃用错误不是故意的。

    在 Node 14.6.0 中,不再为所有 Gulp 任务任务显示此警告(尽管如果您的代码以不推荐的方式使用模块,您的自定义代码可能会触发警告)。

    【讨论】:

      猜你喜欢
      • 2023-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-19
      • 2015-02-26
      • 2020-01-31
      • 2020-05-14
      • 2023-02-08
      相关资源
      最近更新 更多