Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gulp crashes when there's an error in my sass files #44

Closed
kevinSuttle opened this issue Apr 3, 2014 · 23 comments
Closed

Gulp crashes when there's an error in my sass files #44

kevinSuttle opened this issue Apr 3, 2014 · 23 comments

Comments

@kevinSuttle
Copy link

It would be great to avoid having to restart gulp every time I make a typo in my sass file. Is it something I can work around?

@prestyman
Copy link

If you pass errLogToConsole: true into the options hash, sass errors will be logged to the console. Use this option with gulp.watch to keep gulp from stopping every time you make a typo in your sass file.

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

@kevinSuttle
Copy link
Author

I added .pipe(sass({errLogToConsole: true})) and it no longer crashes, but the errors are not logged to the console.

@samvasko
Copy link

@kevinSuttle

I am using:

gulp.task('scss', function() {
    gulp.src('sources/scss/main.scss')
        .pipe(sass())
        .on('error', gutil.log)
        .pipe(gulp.dest('./public/css'));
});

It looks fine but the errors are not really well structured

{ plugin: 'gulp-sass',
  showStack: undefined,
  name: 'Error',
  message: 'sources/scss/forms:20: error: error reading values after display\n',
  fileName: undefined,
  lineNumber: undefined }

@rottmann
Copy link

use gulp-plumber to handle errors

gulp.task('scss', function() {
    gulp.src('sources/scss/main.scss')
        .pipe(plumber())
        .pipe(sass())
        .pipe(gulp.dest('./public/css'));
});

@patrickmarabeas
Copy link

errLogToConsole: true does not work when used with sourceComments: 'map'.

@hotmeteor
Copy link

@rottmann Thanks, that's awesome.

@DESIGNfromWITHIN
Copy link

Thanks @rottmann Love gulp-lumber. Great tip

@lekhnath
Copy link

what a cool name gulp-plumber for preventing pipe breaking . Awesome name and awesome work. Thanks for letting know about it.

@jialezhang
Copy link

nice gulp-plumber!

@jklue
Copy link

jklue commented Sep 16, 2015

@rottmann thank you--better workflow now.

@wwwebman
Copy link

wwwebman commented Nov 3, 2015

@rottmann thanks a lot you awesome!

@Vitegor
Copy link

Vitegor commented Dec 20, 2015

thanks, gulp-plumber is nice thing!

@WuglyakBolgoink
Copy link

plumber without sass({errLogToConsole: true}) doesn't work correct, crashed if found error in sass file...

@kevin-romens
Copy link

@rottmann it's cool thanks

@huyle2607
Copy link

@rottmann How can I use gulp-plumber and browerSync together. It's always crashed when there was a error in sass file whether I installed gulp-plumber or not. Please help me with this one!

@LandonSchropp
Copy link

I'm also the error with sourceComments. Using plumber doesn't seem to help.

@CalebBarnes2
Copy link

Hmm. I tried using gulp-plumber with browsersync and gulp-sass.. It throws the error, doesn't crash the server, but it stops watching my files for changes..

gulp.task('sass', function() {
    return gulp.src("app/scss/*.scss")
        .pipe(plumber())
        .pipe(sass({errLogToConsole: true}))
        .pipe(gulp.dest("app/css"))
        .pipe(browserSync.stream());
});

@martemorfosis
Copy link

@CalebBarnes This worked for me:


gulp.task('sass', function() {
    return gulp.src("./scss/*.scss")
    	.pipe(plumber())
        .pipe(sass({errLogToConsole: true}))
        .on('error', catchErr)
        .pipe(gulp.dest("./css"))
        .pipe(browserSync.stream());
});


function catchErr(e) {
  console.log(e);
  this.emit('end');
}

@ghost
Copy link

ghost commented Apr 24, 2017

Hello. I can't figure out how I can use this.emit('end') inside of bs-config.js file, because i'm using browser-sync without gulp and it crashes when watching files contain error. Thank you!

@generalov
Copy link

Usually gulp-sass stops files processing after an error occured. So some files that do not have any error may remain uncompiled. The gulp-flatmap can be used to handle errors per-file so each file takes a chance to be processed.

var sourcemaps = require('gulp-sourcemaps');
var gulpFlatmap = require('gulp-flatmap');

gulp.task('sass', function () {
 return gulp.src('./sass/**/*.scss')
  .pipe(gulpFlatmap(function (stream) {  // the stream contains a single file 
     return stream
        .pipe(sourcemaps.init())
        .pipe(sass())
        .on('error', sass.logError)
        .pipe(sourcemaps.write('./maps'))
  })
  .pipe(gulp.dest('./css'));
});

@ta-riq
Copy link

ta-riq commented Feb 21, 2018

guys, i found this solution.
Just see this image below. As i'm very lazy at typing a solution. 🥇
screenshot_1

@generalov
Copy link

@ta-riq Emitting the 'end' event prevents gulp crashing in case of an 'error' event has occured. It's a fine solution if you really expect to process files with SASS compiler until a first error.

For example, let's a folder contains three files: bad.scss, good1.scss, and good2.scss. The good2.scss has changed and the bad.scss has an error. Which files will be processed to the dest?

It depends on the order in which gulp.src() emits the files. If bad.scss is emitted the first then no any file will be processed because the pipe receives the 'end' event immediately. So you will not see good2.scss changes nor in the dest folder nor in the browser. If gup.src() emits files in some other order [good2.sass, bad.sass, good1.sass] or [good1.sass, bad.sass, good2.sass] then just a single file will be compiled. But the result is not predictable. Some styles will be updated and some will not.

Since a error event has occurred the stream need to be terminated. Errors can not be just caught and ignored. No other file takes a chance to be processed. There is https://www.npmjs.com/package/gulp-plumber package that tries to prevent 'error' events by monkey patching a pipe. But technically it is a hack and it doesn't work in many cases.

@konstantine811
Copy link

Usually gulp-sass stops files processing after an error occured. So some files that do not have any error may remain uncompiled. The gulp-flatmap can be used to handle errors per-file so each file takes a chance to be processed.

var sourcemaps = require('gulp-sourcemaps');
var gulpFlatmap = require('gulp-flatmap');

gulp.task('sass', function () {
 return gulp.src('./sass/**/*.scss')
  .pipe(gulpFlatmap(function (stream) {  // the stream contains a single file 
     return stream
        .pipe(sourcemaps.init())
        .pipe(sass())
        .on('error', sass.logError)
        .pipe(sourcemaps.write('./maps'))
  })
  .pipe(gulp.dest('./css'));
});

Thank you! It is really help me and fixed but with crashed scss compiler

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests