Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gulp-sass, watch stops when invalid property name

Tags:

node.js

gulp

watch stops when error messages occur.

stream.js:94
      throw er; // Unhandled stream error in pipe.
            ^
source string:51: error: invalid property name 

How I can keep watch running and just to tell me where is the error located.

grunt could deal with errors and doesn't need to stop,

styleSheet.scss:41: error: invalid property name

otherwise, I need to keep typing "gulp" in the command-line when an error occurs.

like image 865
olo Avatar asked Jan 12 '14 21:01

olo


3 Answers

This answer has been appended to reflect recent changes to Gulp. I've retained the original response, for relevance to the OPs question. If you are using Gulp 2.x, skip to the second section


Original response, Gulp 1.x

You may change this default behavior by passing errLogToConsole: true as an option to the sass() method.

Your task might look something like this, right now:

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

Change the .pipe(sass()) line to include the errLogToConsole: true option:

.pipe(sass({errLogToConsole: true}))

This is what the task, with error logging, should look like:

gulp.task('sass', function () {
  gulp.src('./*.scss')
    .pipe(sass({errLogToConsole: true}))
    .pipe(gulp.dest('./'));
});

Errors output will now be inline, like so:

[gulp] [gulp-sass] source string:1: error: invalid top-level expression

You can read more about gulp-sass options and configuration, on nmpjs.org


Gulp 2.x

In Gulp 2.x errLogToConsole may no longer be used. Fortunately, gulp-sass has a method for handling errors. Use on('error', sass.logError):

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

If you need more fine-grained control, feel free to provide a callback function:

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

This is a good thread to read if you need more information on process-control: https://github.com/gulpjs/gulp/issues/259#issuecomment-55098512

like image 186
chantastic Avatar answered Nov 19 '22 19:11

chantastic


Actually above anwsers doesn't work for me (Im using gulp-sass 3.XX). What really worked:

 gulp.task('sass', function () {
    return gulp.src(config.scssPath + '/styles.scss')
        .pipe(sourcemaps.init())
        .pipe(sass({ outputStyle: 'compressed' })
            .on('error', sass.logError)
        )
        .pipe(sourcemaps.write('./'))
        .pipe(gulp.dest(config.cssPath))
});

In gulp-sass 3.x.x when I was using "sass.logError(err);" I constantly recive error that "this.emit('end'); is not a function". Now when I'm using:

.pipe(sass({ outputStyle: 'compressed' })
    .on('error', sass.logError)
 )

everything is working like a charm

like image 11
born2fr4g Avatar answered Nov 19 '22 20:11

born2fr4g


In gulp "^2.0.0" the option errLogToConsole will no longer work. Instead gulp-sass has a built in error logging callback that uses gulp-util under the hood. Also, because gulp has some problems with killing the process on errors, if you are using with watch you will have to call this.emit('end') https://github.com/gulpjs/gulp/issues/259#issuecomment-55098512

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

//dev
sass(config.sassDev)
  .on('error', function(err) {
     sass.logError(err);
       this.emit('end'); //continue the process in dev
     })
)

//prod
sass(config.sassProd).on('error', sass.logError)
like image 6
dtothefp Avatar answered Nov 19 '22 20:11

dtothefp