Gulp encountered an error at line 72 of events.js

I have been experimenting with a jekyll style guide that I found on: https://github.com/davidhund/jekyll-styleguide#user-content-requirements

Here is the gulpfile I am using:

var gulp = require('gulp');
var sass = require('gulp-ruby-sass');
var autoprefixer = require('gulp-autoprefixer');
var browserSync = require('browser-sync');
var rename = require('gulp-rename');
var concat = require('gulp-concat');
var minifycss = require('gulp-minify-css');
var uglify = require('gulp-uglify');
var clean = require('gulp-clean');
var notify = require('gulp-notify');
var plumber = require('gulp-plumber');

// File paths for easy access
paths = {
    scss: "./static/scss/",
    css:  "./static/css/",
    img:  "./static/img/",
    js:   "./static/js/"
}

// SASS task
gulp.task('sass', function() {
    return gulp.src(paths.scss+'app.scss')
        .pipe(sass({ style: 'expanded' }))
        .pipe(autoprefixer('> 5%', 'last 2 version', 'ie 9'))
        .pipe(minifycss())
        .pipe(rename({suffix: '.min'}))
        .pipe(gulp.dest(paths.css))
});

// COPY CSS task
gulp.task('copycss', function() {
    return gulp.src(paths.css+'app.min.css')
        .pipe(gulp.dest('./_site/static/css/'))
});


// JEKYLL tasks
gulp.task('jekyll-build', function() {
    require('child_process').spawn('jekyll', ['build', '--config=_config.dev.yml'], {stdio: 'inherit'});
});

gulp.task('jekyll-watch', function() {
    require('child_process').spawn('jekyll', ['build', '--watch', '--config=_config.dev.yml'], {stdio: 'inherit'});
});

// BROWSER-SYNC task
gulp.task('browser-sync', function() {
    browserSync.init(['./_site/static/**/*.css', './_site/**/*.html'], {
        server: {
            baseDir: './_site/'
        }
    });
});

// WATCH task
gulp.task('watch', function() {
    gulp.watch(paths.scss+'**/*.scss', ['sass', 'copycss']);
});


// DEFAULT task
gulp.task('default', ['jekyll-watch', 'watch','browser-sync']);

However, every time I run gulp, I encounter the following error:

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: spawn ENOENT
    at errnoException (child_process.js:998:11)
    at Process.ChildProcess._handle.onexit (child_process.js:789:34)

Answer №1

The issue you're encountering is due to a lack of error handling in your gulp setup. When an error occurs, gulp throws it, but there's no mechanism in place to handle it, causing gulp to fail.

To continue running gulp smoothly, you need to define error handlers and decide how to manage errors - typically by displaying them in the CLI.

You should also pinpoint where the error is originating from in your code. In this case, it seems that the "watcher" component is responsible for triggering the error.

You must catch the error!

After executing plugins, add an event handler to capture errors and pass them to a function for displaying (or other actions). This way, you can address the error without halting the watch process and manually restarting gulp.

PS: Don't forget to implement the "catcher function"!

Your code could resemble something like this:

// Your Gulp tasks
var gulp = require('gulp');
var sass = require('gulp-ruby-sass');
// Other dependencies...

// Define file paths
paths = {
    scss: "./static/scss/",
    css:  "./static/css/",
    img:  "./static/img/",
    js:   "./static/js/"
}

// SASS task
gulp.task('sass', function() {
    return gulp.src(paths.scss+'app.scss')
        .pipe(sass({ style: 'expanded' })).on('error', errorHandler)
        // Additional processing...
});

// Copy CSS task
gulp.task('copycss', function() {
    // Copy minified CSS...
});

// Jekyll tasks
// More tasks...

// Browser-sync task
// More tasks...

// Watch task
gulp.task('watch', function() {
    // Update tasks when specific files change
    gulp.watch(paths.scss+'**/*.scss', ['sass', 'copycss']);
    // More watch tasks...
});


// Default task
gulp.task('default', ['jekyll-watch', 'watch','browser-sync']);

// Function to handle errors
function errorHandler(error) {
  console.log(error.toString());
  this.emit('end');
}

Make sure to notice the error handler setup at the end and the inclusion of .on('error', errorHandler) in your sass task.

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

Encountering issues with executing NPM commands following the deployment of a React application on GitHub pages

After successfully deploying to github pages for the first time, I encountered errors whenever running NPM commands in my project. The set of errors is as follows: geekcentric => npm start npm ERR! file /mnt/c/Users/GeekCentric/Documents/ReactJS/the_app/ ...

Issue: Unable to locate 'child_process' in Angular 5

I am a newcomer to Angular, and I have encountered a requirement in my project to retrieve the MAC address of the user's system. To achieve this, I performed an NPM installation as shown below: npm install --save macaddress Next, I added the follow ...

Issue with NPM Installation - Microsoft SQL Server Driver

Attempting to set up msnodesql using npm, a library for sql server drivers, on my Windows Server 2012 machine. I've successfully installed Visual C++ 2010, node-gyp, and Python 2.7.x.x as prerequisites. However, when I try running npm install msnode ...

Error message: Unable to modify the 'cflags' property of object '#<Object>' in Angular CLI and node-gyp

@angular/cli has a dependency on node-gyp, which is evident from the following: npm ls node-gyp <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="16776666653b7477757d7970707f7573562738263826">[email protected]</a> /h ...

Installing packages globally and locally with npm leads to the installation of varying components

There seems to be a discrepancy in the results I get when installing a package with --global compared to a local installation. For instance I recently installed https://github.com/sverweij/dependency-cruiser $ npm install --save-dev dependency-cruiser W ...

encountering an issue: "trigger new TypeError('JwtStrategy needs a secret or key');"

While attempting to run my web application, I encountered the following error: throw new TypeError('JwtStrategy requires a secret or key'); ^ TypeError: JwtStrategy requires a secret or key at new JwtStrategy (/Users/smitsanghvi/Des ...

Establishing a link to MongoDB through the use of mongoose

Currently, I am utilizing the Gulp build system. Upon attempting to establish a connection to my local MongoDB through mongoose, an error message displaying "mongoose.connect is not a function" appears. The snippet of code used for connecting is as follow ...

The attempt to generate a Base Amplify Project using npx amplify-app@latest was unsuccessful

Trying to set up a react-app following these steps: npx create-react-app amplify-datastore --use-npm cd amplify-datastore npx amplify-app@latest #here's the output I see in powershell: npx: installed 117 in 15.511s ✅ Found Amplify CLI version 4.29 ...

I'm encountering some errors while trying to deploy on Vercel. Is there anyone who could lend a hand with the following issues I'm

Cloning repository github.com/gmcnally78/-Final-Data-Driven-FullStack-App2 (Branch: main, Commit: e1d0133) Clone process completed in: 643.936ms Analyzing source code... Installing build runtime... Build runtime installation time: 2.278s Checking for ...

When switching versions of Node using nvm, Powershell fails to recognize npm

Having an issue with my powershell script. I'm attempting to develop a project using node version 10.17.0 and then transfer the outcome to another project operating on node version 8.11.4 and execute the project. cd $PathToWebLibs Write-Host " ...

Wait until the document is fully loaded before importing npm in ReactJS/Next.js applications

Recently, I encountered an issue while trying to utilize a small js library named float-sidebar.js. After installing the module through npm, I realized that in React, it was throwing an error stating "window" is not defined. This problem arose because the ...

Run an npm script located in a different package

Imagine I have two node packages, one named parent and the other named child. The child package contains a package.json file with some scripts. Is it viable to merge the scripts from child into the context of parent? For instance: child/package.json: "s ...

Encountering an unexpected issue while attempting to execute npm publish command

After consistently publishing this package on a weekly basis for many years, I encountered an unexpected error today when attempting to update the version and publish it: npm notice name: mypackagename npm notice version: 6.18.4 npm notice p ...

Create a custom npm package that is compatible with frontend environments like create-react-app. Ensure you have a suitable loader in place to handle the specific file type of the module

After developing a node module and releasing it as a node package, I encountered an issue when trying to use it in frontend applications (specifically with a 'create-react-app'). The error message that appeared stated: Module parse failed: Unexp ...

Node.js ACL system centered around connections

In my Node.js project, I am working on setting up a permission framework using Sequelize as an ORM with Postgres. Despite conducting extensive research, the closest solution I have found utilizing existing npm modules is by implementing acl combined with a ...

The npm run dev command is failing to recognize the updated sass division format

To get ready for the release of Dart Sass 2.0.0, I've been diligently following the guidelines to update the divisions in my scss files from slashes to the "divide" function. You can find more information on this migration process here: https://sass-l ...

How to remove various items from Google Cloud Storage with node.js

I'm looking to mass delete multiple objects from Google Cloud Storage. Currently, I've been deleting one object at a time using the following code: var gcloud = require('gcloud')({ projectId: "sampleProject1" }); var gcs = gcloud.sto ...

Providing parameters to a testing script during the execution of unit tests using hardhat

Currently, I have a set of unit tests that are designed to test some solidity smart contracts. Everything is working smoothly, but I have come across a minor issue. The location of the solidity smart contract file is hardcoded into the javascript test file ...

The issue with Laravel Elixir BrowserSync not displaying the page

After checking out the latest episode on TechSavy Forums () I was inspired to experiment with CodePen for web development. First, I followed the usual steps for starting a new project: npm init cd project npm install Next, I attempted to access the Code ...

An AggregateException has occurred due to multiple errors arising. The main issue revolves around the failure to initiate the 'npm' application. To troubleshoot this problem and resolve it, further actions are

Experiencing frustration with Visual Studio on Mac when using Docker due to numerous errors. The project involves ASP.NET Core 2.1 with Angular 6 on a Docker image. The project builds successfully, but encounters issues when trying to run as detailed below ...