R
R
RedSmoke_smr2019-10-27 20:35:18
JavaScript
RedSmoke_smr, 2019-10-27 20:35:18

Why does gulp throw an error Error: write callback called multiple times when compiling?

Hello!
Can you please tell me why when compiling gulp it gives an error Error: write callback called multiple times?
I downloaded the starter template from github, it was fully configured with all tasks, etc. (I still don’t understand writing tasks for gulp), when I run gulp (with the gulp command in the console), all my code compiles perfectly from scss and pug into plain css and html with pictures. I completed the entire layout, and as the author of the template said, that at the end, when everything is finished, you need to write the gulp build command in the console and then the project will be assembled with all minified files and compressed graphics. But when I write gulp build in the console, the execution of all tasks starts, and when passing the 'img: build' task, it gives an error.
Please help me figure this out, is there a mistake somewhere?
I am attaching the task code:

let imagemin = require('gulp-imagemin'),
    imageminJpegRecompress = require('imagemin-jpeg-recompress'),
    pngquant = require('imagemin-pngquant'),
    cache = require('gulp-cache'),
    imgPATH = {
        "input": ["./dev/static/images/**/*.{png,jpg,gif,svg}",
            '!./dev/static/images/svg/*'],
        "output": "./build/static/images/"
    };

module.exports = function () {
    $.gulp.task('img:dev', () => {
        return $.gulp.src(imgPATH.input)
            .pipe($.gulp.dest(imgPATH.output));
    });

    $.gulp.task('img:build', () => {
        return $.gulp.src(imgPATH.input)
            .pipe(cache(imagemin([
                imagemin.gifsicle({interlaced: true}),
                imagemin.jpegtran({progressive: true}),
                imageminJpegRecompress({
                    loops: 5,
                    min: 70,
                    max: 75,
                    quality: 'medium'
                }),
                imagemin.svgo(),
                imagemin.optipng({optimizationLevel: 3}),
                pngquant({quality: '65-70', speed: 5})
            ], {
                verbose: true
            })))
            .pipe($.gulp.dest(imgPATH.output));
    });
};

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
RedSmoke_smr, 2019-10-29
@RedSmoke_smr

Figured it out myself. The error was in this task - $.gulp.task('img:build', ()
I did not fix it much, and everything worked.
Below is the code of the working function:

$.gulp.task('img:build', () => {
        return $.gulp.src(imgPATH.input)
            .pipe(imagemin([
                imagemin.gifsicle({interlaced: true}),
                imageminJpegRecompress({
                    loops:4,
                    min: 70,
                    max: 75,
                    quality:'medium'
                }),
                imagemin.optipng(),
                imagemin.svgo(),
                imagemin.optipng({optimizationLevel: 3}),
                pngquant({quality: [0.65, 0.7], speed: 5})
            ], {
                verbose: true
            }))
            .pipe($.gulp.dest(imgPATH.output));
    });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question