Gulp-sass: Error when calling logError callback on error

Created on 10 Dec 2015  路  7Comments  路  Source: dlmanning/gulp-sass

This is a simple task to compile sass to css with sourcemaps:

gulp.task('sass', function () {
    gulp.src(['*.scss'])
        .pipe(sourcemaps.init())
        .pipe(sass().on('error', sass.logError))
        .pipe(sourcemaps.write('./'))
        .pipe(gulp.dest('dist'));
});

I'm getting this error if there is a syntax error on sass file:

/Users/lm/Sites/app/node_modules/gulp-sass/index.js:170
  this.emit('end');
       ^
TypeError: undefined is not a function
    at Function.logError (/Users/lm/Sites/app/node_modules/gulp-sass/index.js:170:8)
    at DestroyableTransform.<anonymous> (/Users/lm/Sites/app/gulpfile.js:109:16)
    at DestroyableTransform.emit (events.js:129:20)
    at onwriteError (/Users/lm/Sites/app/node_modules/gulp-sass/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:345:10)
    at onwrite (/Users/lm/Sites/app/node_modules/gulp-sass/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:363:5)
    at WritableState.onwrite (/Users/lm/Sites/app/node_modules/gulp-sass/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:123:5)
    at afterTransform (/Users/lm/Sites/app/node_modules/gulp-sass/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:84:5)
    at TransformState.afterTransform (/Users/lm/Sites/app/node_modules/gulp-sass/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:59:12)
    at errorM (/Users/lm/Sites/app/node_modules/gulp-sass/index.js:123:14)
    at Object.callback (/Users/lm/Sites/app/node_modules/gulp-sass/index.js:134:18)
more info needed

Most helpful comment

I wanted to write a 'beep' to the console by creating my own error callback. The trick is to manually bind the logError function:

.pipe(sass({...})
.on('error', function(err) {
  console.error('\x07'); // so it doesn't just fail (literally) silently!
  sass.logError.bind(this)(err);
}))

The syntax is a bit ridiculous, but it works!

All 7 comments

Do you have a reproduction in a repo ?

I run in the same issue. The problem occurs when you replace:

gulp.task('sass', function (done) {
    gulp.src(['*.scss'])
        .pipe(sass().on('error', sass.logError))
        .pipe(gulp.dest('dist'))
        .on('end', done)
});

for

gulp.task('sass', function (done) {
    gulp.src(['*.scss'])
        .pipe(sass().on('error', function(error)
        {
            sass.logError(error)
            done()
        }))
        .pipe(gulp.dest('dist'))
        .on('end', done)
});

I need to call done function in order to get watch working. Otherwise, the error don't break the stream, but the watch stops working because the task never ends.

The problem comes from line

this.emit('end')

The "this" is not bind, and there is no clue what it must be.

I'm running into the same issue. While I'm able to work around that by using gulp-plumber I would prefer to do that without yet another plugin.

@xzyfer The basic issue is that gulp-sass doesn't work when used with watch and all the examples I can find seem to be outdated / don't work. If you are having trouble to reproduce this I'm happy to provide an example but could you point me at some documentation / example that is supposed to be working?

@digital-wonderland a reproduction repository is probably the only way we'll be able to progress this issue. Most of our issues are cause by incorrect configuration or broken plugins in the pipeline which make them impossible for us to reproduce. Below are some examples of previous reproduction repositories.

https://github.com/doginthehat/gulp-sass-bug-test
https://github.com/doginthehat/gulp-sass-bug-test

I wanted to write a 'beep' to the console by creating my own error callback. The trick is to manually bind the logError function:

.pipe(sass({...})
.on('error', function(err) {
  console.error('\x07'); // so it doesn't just fail (literally) silently!
  sass.logError.bind(this)(err);
}))

The syntax is a bit ridiculous, but it works!

@alalonde binding the logError worked for me!

Closing as stale. There appear to be work arounds.

Was this page helpful?
0 / 5 - 0 ratings