Gulp JS task is generating a NodeError due to the callback being triggered more than once

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 and minify functions, yet the error persisted, indicating a possible issue with the gulp_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

Answer №1

It seems that the issue lies not with the plugin itself. The error may be occurring because there is a file (A) calling another file (B) which in turn calls back to the initial file (A), creating a loop. I recommend thoroughly reviewing the files to prevent getting stuck in this loop.

If you have a large number of files, you can also try using git checkout to revert to a previous point in history. Once you identify a successful commit, you can compare it with the current version using git diff to see which files have changed.

Additionally, it is not necessary to add prefix and basepath properties to fileinclude as they are set to their default values.

I hope this information proves helpful.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for disregarding single quotation marks in the validator.js function for checking alphanumeric characters

I am currently working on validating a string using express validator, specifically utilizing the isAlphanumeric function. However, I would like to include space, dash, and single quote as acceptable characters in the validation process. Below is the code ...

Exploring ways to locate a specific text within a URL using nodeJS

Here is a simple code snippet with a problem to solve: var S = require('string'); function checkBlacklist(inputString) { var blacklist = ["facebook", "wikipedia", "search.ch", "local.ch"]; var found = false; for (var i = 0; i < b ...

observing calls made with twilio using javascript

My goal is to track the status of a phone call happening between two people using their phone numbers. Let's say +558512344321 and +558543211234 are currently on a call. As soon as the call begins, I want the browser to display "Call in progress," and ...

Having trouble installing NPM Live-server on zsh shell?

As I attempt to globally install live-server using the command: npm install -g live-server, I continue to encounter the following error message; mac@Edozie ~ % npm install -g live-server npm WARN deprecated <a href="/cdn-cgi/l/email-protection" class="_ ...

What is the best way to send a file and retrieve a value on Internet Explorer versions 8 and 9?

Greetings everyone, I am encountering a technical issue that has consumed a significant amount of my time. I am hopeful that you may be able to assist me with resolving it. In my table, I have a list of files along with corresponding document types and de ...

Displaying the contents of a local HTML file in a div

I am attempting to load a local HTML file into a div, however it is not displaying any content on the page despite showing an alert. Here is the HTML code: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> ...

I would like to know more about the concept of getters and setters and how they can be effectively utilized

I've been struggling to understand the concept of getters and setters. Despite reading articles like JavaScript Getters and Setters and Defining Getters and Setters, I just can't seem to grasp it. Could someone please explain: The purpose of g ...

Implementing clickable table rows in React Router Link for seamless navigation

I'm relatively new to working with React. In my project, there is a Component called Content, which acts as a container for two other components - List and Profile. class Content extends Component{ <HashRouter> <Route exact path="/ ...

Modifying property values using the onError event when encountering an error with the MUI DateTimePicker and

My goal is to set the 'myError' variable to true when MUI DateTimePicker throws an onError event, but for some reason it's not working. The code itself seems correct because if I replace () => {setValue({ ...value, ...

Is there a way to eliminate duplicate elements from 2 arrays in Angular?

Imagine I have a scenario with two arrays: arr1 = ["Tom","Harry","Patrick"] arr2 = ["Miguel","Harry","Patrick","Felipe","Mario","Tom"] Is it possible to eliminate the duplicate elements in these arrays? The desired output would be: arr2 = ["Miguel"," ...

I'm looking to fill multiple input boxes with the same value

I am looking to pass the same value to multiple input boxes. Currently, the script below only displays in one box but I want to display the main box result in all multiple input boxes. <script type='text/javascript' src='http://code.jque ...

Alter the background color of a React application with a single click in a spontaneous manner

When I attempted to change the background color of the entire page randomly by clicking a button, it only changed the background of the div element. Here is the code snippet I used: import React from "react"; class Home extends React.Component { ...

Sending AJAX data from VIEW to CONTROLLER in PHP (MVC) using AJAX: A step-by-step guide

I have a page at http://visiting/blog. The Controller contains two methods: action_index and add_index. When Action_index() executes, it returns pages with indexes. On the other hand, Add_index() invokes a model's method called add_data(), which inse ...

React Jodit Editor experiencing focus loss with onchange event and useMemo functionality not functioning properly

I'm currently working on a component that includes a form with various inputs and a text editor, specifically Jodit. One issue I've encountered is that when there are changes in the Jodit editor's content, I need to retrieve the new HTML va ...

What is the best way to verify the existence of an email address?

I'm currently using the jQuery validation plugin and everything is working fine, but I've hit a snag when it comes to checking email addresses. The issue is that the plugin returns either true or false based on whether the email exists or not. Ho ...

Navigating through JQuery

Is there a way to scroll to a div + 100px specifically on the y axis? I am unsure how to achieve this. Can you provide guidance? I attempted using $.scrollTo('div100' + '100px', 2000) but unfortunately, it did not produce the desired ...

Jquery script that utilizes the Steam WebAPI to return data

I'm encountering an issue with a script I found on github. I added value.appid myself, thinking it was logical, but I believe that data.response.games contains values for all my games. How can I either print or view what is defined? I would like to ...

Quickly redesigning the appearance of file input using javascript and jquery. Seeking assistance to correct css issues on jsfiddle

Hey there, I've been working on styling the input[type="file"] element and could use some assistance. Like the saying goes, "One JSfiddle is worth 1000 words," so here's the link to my example: --- For more details, click here: http://jsfiddle.n ...

When passing data to a controller through fetch in Codeigniter 3, the data may sometimes become null

I am facing an issue where I have data that needs to be sent from a view to a controller using fetch, but the data appears as null in the controller despite being successfully sent with a status of 200. Does anyone have a solution to ensure that the data i ...

Encountering issues with Node-persist on a complex Node.js application leading to missing return

I've encountered an issue with my heavy node app where I'm using node-persist to save data locally. Specifically, in a certain step of the process, I have the following code: const localdb = require('node-persist') const storage = loca ...