Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
363 views
in Technique[技术] by (71.8m points)

node.js - gulp-sass, watch stops when invalid property name

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.

question from:https://stackoverflow.com/questions/21080433/gulp-sass-watch-stops-when-invalid-property-name

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...