Jshint crashing gulp when a javascript error occurs

Hi all,

When I have an error in my javascript, jshint crashes my gulp watch script and I need to restart it in order to continue working. It’s quite frustrating and I’m sure a few people have also encountered this issue.

Could someone recommend a solution which would just display the error and not build the javascript, instead of crashing the gulp watch process please?

➜  my_theme git:(master) ✗ gulp watch
[08:29:32] Using gulpfile ~/Development/my_website/site/web/app/themes/my_theme/gulpfile.js
[08:29:32] Starting 'watch'...
[08:29:32] Finished 'watch' after 54 ms
[BS] Proxying: http://my_website.dev
[BS] Access URLs:
       Local: http://localhost:3000
          UI: http://localhost:3001
 UI External:
[BS] Watching files...
[08:29:38] Starting 'jshint'...

  line 78  col 25  Expected an identifier and instead saw '.'.
  line 78  col 25  Expected an assignment or function call and instead saw an expression.
  line 78  col 26  Missing semicolon.

  ✖  2 errors
  ⚠  1 warnings

[08:29:38] Finished 'jshint' after 305 ms
[08:29:38] Starting 'scripts'...

      throw er; // Unhandled stream error in pipe.
    at new JS_Parse_Error (eval at <anonymous> (/home/james/Development/my_website/site/web/app/themes/my_theme/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:24:4), <anonymous>:1526:18)
    at js_error (eval at <anonymous> (/home/james/Development/my_website/site/web/app/themes/my_theme/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:24:4), <anonymous>:1534:11)
    at croak (eval at <anonymous> (/home/james/Development/my_website/site/web/app/themes/my_theme/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:24:4), <anonymous>:2026:9)
    at token_error (eval at <anonymous> (/home/james/Development/my_website/site/web/app/themes/my_theme/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:24:4), <anonymous>:2034:9)
    at unexpected (eval at <anonymous> (/home/james/Development/my_website/site/web/app/themes/my_theme/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:24:4), <anonymous>:2040:9)
    at eval (eval at <anonymous> (/home/james/Development/my_website/site/web/app/themes/my_theme/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:24:4), <anonymous>:2130:17)
    at eval (eval at <anonymous> (/home/james/Development/my_website/site/web/app/themes/my_theme/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:24:4), <anonymous>:2073:24)
    at block_ (eval at <anonymous> (/home/james/Development/my_website/site/web/app/themes/my_theme/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:24:4), <anonymous>:2353:20)
    at eval (eval at <anonymous> (/home/james/Development/my_website/site/web/app/themes/my_theme/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:24:4), <anonymous>:2120:29)
    at eval (eval at <anonymous> (/home/james/Development/my_website/site/web/app/themes/my_theme/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:24:4), <anonymous>:2073:24)
    at if_ (eval at <anonymous> (/home/james/Development/my_website/site/web/app/themes/my_theme/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:24:4), <anonymous>:2336:44)


I was helping someone out earlier with a similar issue. Did you do anything out of ordinary?

Our errors were a tad different, but I assumed it was because we installed an older theme into a newer version of Tellis/Bedrock.

What eventually fixed it I believe was a vagrant destroy. Then made sure the etc/hosts file was clean. Then we vagrant’ed back up.

Ran gulp, then gulp watch- and it worked.

Maybe I’m forgetting one crucial step we did, but I think that was it, let me know if that works. It’s confusing, I don’t know why that fixed ‘gulp watch’ but it was working fine after that.

It’s an error related to the gulp pipeline not handing errors for jshint, which results in gulp crashing. It’s for the sage theme, I’m using the latest version from github.

By default, Plumber is not piped in your scripts task but it’s already included in the packages loaded via npm.
You can replace your scripts task with the following

var onError = function (err) {

gulp.task('scripts', ['jshint'], function() {
  var merged = merge();
  manifest.forEachDependency('js', function(dep) {
      gulp.src(dep.globs, {base: 'scripts'})
        .pipe(plumber({ errorHandler: onError }))
  return merged

Perfect, thanks very much Nicolo.

Nicolo’s solution should be standard in the Sage gulpfile.

Any reason why it isn’t? I can’t imagine having it crashing and forcing the dev to run gulp watch manually each time is more efficient :stuck_out_tongue:

I think the dev focus is now on Sage 9, which no longer uses Gulp. But I’m sure they’d look at a pull request if you made one!

If someone wants to PR the 8.5.0 branch with:

We’d be open to accepting it and tagging a maintenance release. The 8.x branch also could use a bump on the Bootstrap 4 alpha version.

On it: https://github.com/roots/sage/pull/1779