【问题标题】:The error "TypeError: dest.on is not a function" for gulp-webp when trying to convert images尝试转换图像时 gulp-webp 的错误“TypeError:dest.on 不是函数”
【发布时间】:2022-03-27 08:31:22
【问题描述】:

我的代码中的任务有问题。我有一些图像,我想使用“gulp-webp”模块将它们从 .jpg 转换为 .webp,但是当我在终端上运行 gulp 函数时,会出现以下错误:

[00:00:00]Starting 'versionWebp'...
[00:00:00]'versionWebp' errored after 8.92 msTypeError: dest.on is not a function
[00:00:00]at DestroyableTransform.Readable.pipe (D:\Cursos\Curso 06\FestivalMusica_inicio\node_modules\readable-stream\lib\_stream_readable.js:564:8)
at versionWebp (D:\Cursos\Curso 06\FestivalMusica_inicio\gulpfile.js:60:10)
at taskWrapper (D:\Cursos\Curso 06\FestivalMusica_inicio\node_modules\undertaker\lib\set-task.js:13:15)
at bound (node:domain:421:15)
at runBound (node:domain:432:12)
at asyncRunner (D:\Cursos\Curso 06\FestivalMusica_inicio\node_modules\async-done\index.js:55:18)
at processTicksAndRejections (node:internal/process/task_queues:78:11).

我的代码是这样的

const notify = require('gulp-notify');
const webp = require ('gulp-webp');

function versionWebp(){
return src('src/img/**/*')
    .pipe( webp )
    .pipe(gulp.dest('./build/img'))
    .pipe(notify({message:'Version WEBP'}));
};

exports.versionWebp = versionWebp;

希望你能帮助我。

【问题讨论】:

  • 使用.pipe(webp()) 而不是.pipe(webp)

标签: image compiler-errors gulp development-environment webp


【解决方案1】:

webp结尾必须有(),必须是函数;代码将是:

function versionWebp(){
   return src('src/img/**/*')
      .pipe( webp() )
      .pipe(gulp.dest('./build/img'))
      .pipe(notify({message:'Version WEBP'}));
};

【讨论】:

    猜你喜欢
    • 2016-08-22
    • 1970-01-01
    • 1970-01-01
    • 2017-04-24
    • 1970-01-01
    • 1970-01-01
    • 2021-08-17
    • 2018-07-08
    • 2020-08-16
    相关资源
    最近更新 更多