Error Encountered in Gulp JS Task - NodeError: Callback called multiple times
Among the five Gulp JS tasks that I have, one specific task named js_bundle
is causing a NodeError. The exact error message is:
NodeError: Callback function called multiple times
Below is a snippet of my gulpfile.js
:
const { src, dest, parallel , series , watch } = require('gulp');
const sass = require('gulp-sass')(require('sass'));
const fileinclude = require('gulp-file-include');
const sourcemaps = require('gulp-sourcemaps');
const uglify = require('gulp-uglify');
const minify = require('gulp-minifier');
const strip = require('gulp-strip-comments');
const rtlcss = require('gulp-rtlcss');
const rename = require('gulp-rename');
// sass.compiler = require('node-sass'); // no-need for gulp-sass v5+
var node_path = '../../..//';
function html(cb) {
src('html/src/**')
.pipe(dest('html/dist/'));
cb();
}
function scss(cb) {
src(['scss/*.scss'])
.pipe(sass().on('error', sass.logError))
.pipe(dest('assets/dist/css'));
src(['scss/*.scss', '!scss/style-email.scss'])
.pipe(sass().on('error', sass.logError))
.pipe(rtlcss())
.pipe(rename({ suffix: '.rtl' }))
.pipe(dest('assets/dist/css'));
// More scss tasks here...
cb();
}
function js_scripts(cb) {
// js_scripts task logic...
cb();
}
function js_bundle(cb) {
// js_bundle task logic...
cb();
}
function assets(cb){
// assets task logic...
cb();
}
exports.build = series(html, scss, js_scripts, js_bundle, assets);
exports.develop = function() {
// watch tasks...
};
Here is the part of the code where the issue arises:
.pipe(fileinclude({
prefix: '@@',
basepath: '@file',
context: { build: 'dist', nodeRoot: node_path }
}))
Steps tried to resolve the issue:
- Updated the
gulp_file_include
plugin to the latest version suspecting it to be the culprit. - Checked function calls for callback repetition by console logging before and after, but found no resolution.
- Removed
strip
andminify
functions, yet the error persisted, indicating a possible issue with thegulp_file_include
plugin. - Referenced a related Stack Overflow question How to fix callback function called multiple times where a similar problem was tied to the
gulp-imagemin
plugin, which I do not have installed.
Any assistance in resolving this error is greatly appreciated. Thank you, Ciao