gulp-sass: Stops writing CSS after first error in SASS

First, I’ve reported this issue under floatdrop/gulp-watch#86 thinking it was related to gulp-watch, but then I’ve realized that the issue is gone when I replace gulp-sass with gulp-less, so I thought maybe this is a gulp-sass related issue after all.

TL;DR: gulp-sass()stops piping files to destination after a SASS error occurs. Need to restart gulp for the problem to go away.

Detail:

  1. When SASS files are error free, I see ‘Writing sass’ message each time I update a *.scss file.
  2. Then, I deliberately introduce an error into one of the SASS files. I see an error message from gulp-plumber as I should.
  3. However, when I undo this error, I no longer see “Writing sass” message and no CSS files are being written to the .build/ directory. I need to restart gulp watch-sass task to make things go back to normal.
# In gulpfile.coffee
sass = require("gulp-sass")
... ... ...
gulp.task "watch-sass", ->
  watch
    glob: filePath.appDir + "/**/*.scss"
  .pipe plumber()
  .pipe sass() # the problem goes away if I replace `sass` with `less`
  .pipe using prefix: "Writing sass" 
  .pipe gulp.dest('.build/')
  return  

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Reactions: 3
  • Comments: 23 (1 by maintainers)

Commits related to this issue

Most upvoted comments

I just re-tested this and it seems to be working fine when using .on('error', sass.logError). Can someone double check this for me? @dlmanning @Keats @demisx

npm install gulp-sass@next --save-dev

Specifically, what I was running is as follows:

'use strict';

var gulp = require('gulp'),
    sass = require('gulp-sass');


gulp.task('sass', function () {
  gulp.src('./sass/**/*.scss')
    .pipe(sass().on('error', sass.logError))
    .pipe(gulp.dest('./css'));
});

gulp.task('sass:watch', function () {
  gulp.watch('./sass/**/*.scss', ['sass']);
});

Running sass:watch

Hi, I found this issue after researching a bit about how to use gulp-sass with plumber. I understood that in order to keep the watch task alive I need to either:

  1. omit the return statement for the pipe
  2. OR use the sync method as @backflip suggested (btw. thanks for that!)

However I don’t think this is an optimal solution because either you loose:

  1. async task support, when you omit return and don’t thus don’t return the stream
  2. OR you loose concurrency execution

And both of them are great advantages of gulp which I don’t want to loose when I’m using gulp-sass.

Minimal case, where returning the stream is beneficial for the overall execution time:

'use strict';

var gulp = require('gulp');
var sass = require('gulp-sass');

gulp.task('build', ['sass', 'some-other-task'], function () {
  var stream = gulp.src('.');
  // awesome build logic
  return stream;
});

gulp.task('sass', function () {
  // IMPORTANT:
  // 1. stream needs to be returned so 'build' task will wait
  // 2. no sync so 'some-other-task' can execute concurrently
  return gulp.src('./sass/**/*.scss')
    .pipe(sass.on('error', sass.logError))
    .pipe(gulp.dest('./css'));
});

gulp.task('sass:watch', function () {
  gulp.watch('./sass/**/*.scss', ['sass']);
});

What do you guys think? I’m switching from gulp-ruby-sass to gulp-sass and I would really like to see this working in gulp-sass as well!

I understand people are still having issues, so for those who are, please try the following:

  1. The code from https://github.com/dlmanning/gulp-sass/issues/90#issuecomment-89066953 EXACTLY as it appears (Please Note that it does not return the task innards)
  2. The code from https://github.com/dlmanning/gulp-sass/issues/90#issuecomment-100021202 EXACTLY as it appears (Please Note that it does return the task innards and uses Gulp Plumber)

If neither of these things work for you, please provide the following:

  • Create locally the absolute smallest reduced use case where you see the problem happening. Fewest Gulp pipes possible, least amount of Sass possible, smallest number of dependencies.
  • A Gist containing separate files for your exact Gulpfile.js, package.json, and Sass files
  • Your Node version
  • Your Operating System

I had to switch to the sync version to make this work.

Not working:

gulp.task('css', function() {
    return gulp.src('./source/assets/css/*.scss')
        .pipe(plumber())
        .pipe(sass().on('error', sass.logError))
        .pipe(gulp.dest('./build/'));
});

Working:

gulp.task('css', function() {
    return gulp.src('./source/assets/css/*.scss')
        .pipe(plumber())
        .pipe(sass.sync().on('error', sass.logError))
        .pipe(gulp.dest('./build/'));
});

OS X Yosemite Node 0.10.38 gulp 3.8.11 gulp-plumber 1.0.0 gulp-sass 2.0.0