TypeError:dest.on不是gulp中的函数

时间:2019-01-24 23:53:52

标签: gulp

当我在主题源文件夹中编辑主题.yml文件时,出现此错误。当我仅在主文件夹中从模板文件夹编辑scss或模板.yml文件时,不会发生这种情况。其他发生此错误的人使用的是像webpack这样的东西,而我没有。 copy_theme_files的gulp任务与其他任务相同,区别在于它没有返回,因为我不知道如何使用两个gulp.src函数返回那里。

gulp.task('copy_theme_files', function() {
    console.log('[copy_theme_files] Console Log: copy '+paths.themeSrc+' to '+paths.themeDest);
    gulp.src(paths.themeSrc)
        .pipe(gulp.dest(paths.themeDest));
    gulp.src(paths.root + '/*.{png,ico,svg}')
        .pipe(paths.themeDest);
});

完整的gulpfile.js https://pastebin.com/NWt2uMwV

错误输出:

[00:37:58] Using gulpfile /var/www/themes.src/mytheme.src/gulpfile.js
[00:37:58] Starting 'watch'...
[00:38:20] Starting 'copy_theme_files'...
[copy_theme_files] Console Log: copy *.{yml,theme,php,png,jpg,gif,svg,ico},.gitkeep to build
[00:38:20] 'copy_theme_files' errored after 23 ms
[00:38:20] TypeError: dest.on is not a function
    at DestroyableTransform.Readable.pipe (/var/www/themes.src/mytheme.src/node_modules/readable-stream/lib/_stream_readable.js:564:8)
    at /var/www/themes.src/mytheme.src/gulpfile.js:122:10
    at taskWrapper (/var/www/themes.src/mytheme.src/node_modules/undertaker/lib/set-task.js:13:15)
    at bound (domain.js:395:14)
    at runBound (domain.js:408:12)
    at asyncRunner (/var/www/themes.src/mytheme.src/node_modules/async-done/index.js:55:18)
    at process._tickCallback (internal/process/next_tick.js:61:11)
[00:38:20] Starting 'copy_includes'...
[copy_includes] Console Log: copy includes/**/*.*,includes/**/.gitkeep to build/includes
[00:38:20] Finished 'copy_includes' after 7.41 ms
[00:38:20] Starting 'copy_build'...
[copy_build] Console Log: copy build/**/*.*,build/**/.gitkeep to ../../web/themes/local/mytheme
[00:38:20] Finished 'copy_build' after 60 ms

其他任务运行正常

[00:41:06] Starting 'copy_templates'...
[copy_templates] Console Log: copy templates/**/*.twig,templates/**/.gitkeep to build/templates
[00:41:08] Finished 'copy_templates' after 1.86 s
[00:41:08] Starting 'copy_build'...
[copy_build] Console Log: copy build/**/*.*,build/**/.gitkeep to ../../web/themes/local/mytheme
[00:41:09] Finished 'copy_build' after 326 ms

1 个答案:

答案 0 :(得分:1)

您的任务中有此行:

.pipe(paths.themeDest);

您可能是说:

.pipe(gulp.dest(paths.themeDest));

对于其他问题,请查看merging two gulp.src streams的返回方式:

var merge = require('merge-stream');

gulp.task('copy_theme_files', function() {
    console.log('[copy_theme_files] Console Log: copy '+paths.themeSrc+' to '+paths.themeDest);

    const themesStream = gulp.src(paths.themeSrc)
        .pipe(gulp.dest(paths.themeDest));

    const imagesStream = gulp.src(paths.root + '/*.{png,ico,svg}')
        .pipe(paths.themeDest);

    return merge(themesStream , imagesStream );
});