1

I have a very simple Gulpfile:

var gulp = require('gulp'),
    prefix = require('gulp-autoprefixer'),
    gsass = require('gulp-sass');
gulp.task('sass', function() {
    gulp.src('scss/*.scss')
        .pipe(gsass({
            unixNewlines: true,
            style: 'compact'
        }))
        .pipe(prefix('last 2 versions'))
        .pipe(gulp.dest('.'));
});

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

When the SCSS file is changed and the sass task runs, I occasionally (about 10% of the time) get the following error message on the console:

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: EBUSY, open 'C:\whatever\scss\main.scss'

The error in question happens during the call to gulp.src. Passing the read: false option into that function stops the error from happening (but, of course, prevents sass from working).

This error is a problem because the watch task stops running whenever the error is encountered. Neither gulp-plumber nor .on('error', ...) help with this problem.

Is there a way to work around this issue? I'm on Windows, if it's relevant.

A few more relevant points:

  • Removing sass entirely doesn't fix the issue.
  • Putting a try/catch around the contents of either task also doesn't work.
  • I'm using Sublime Text 3 to edit the file. I think the problem is that gulp.src tries to read the file while Sublime is still writing to it (though I'm not entirely sure).
jasonhansel
  • 642
  • 9
  • 14
  • Not sure if it's going to help with this issue, but you should be returning the stream you create with `gulp.src` - i.e. `return gulp.src().pipe(gulp.dest());` – Ben Nov 24 '14 at 00:39

2 Answers2

3

There is a decent chance you have one of your files open in Microsoft Word. Word locks up access to the file. Completely exit MS Word and re-build. Fixed the problem for me. Hope it helps!

Eleanor Zimmermann
  • 414
  • 1
  • 8
  • 26
  • 1
    I don't think so. These are code files, not ones I would open in word. – jasonhansel Jun 22 '15 at 20:01
  • 1
    Is it possible you right-clicked and opened it there accidentally? Certainly, I know one doesn't intentionally edit code in Word. But human error is a thing. Maybe it's not Word and just some other program that's locking up the file. Possibly a second instance of localserver is running? – Eleanor Zimmermann Jun 22 '15 at 21:10
0

So I'm not entirely sure about this because I don't run Windows, but here's some pointers:

  • Like I mentioned in the comment, always return your streams from gulp tasks. That way gulp's task manager knows when the task finishes and can properly sequence your dependencies.
  • If you are overwriting files that are being used by the system, it's not recommended. See this issue for a little more detail: https://github.com/joyent/node/issues/3017
  • I'm not sure this will help either, but you could try writing your compiled CSS into a subdirectory, say ./dist/css or something along those lines.
  • It may be worth opening an issue (after trying the above points first!) on vinyl-fs which is the module used for gulp.src etc.
Ben
  • 10,106
  • 3
  • 40
  • 58
  • Thanks for your help! The first three suggestions didn't work, unfortunately; I think I am going to follow your fourth one. I'll probably file a bug on gulp rather than vinyl-fs, however, since I suspect this may also be an issue with gulp.watch. – jasonhansel Nov 26 '14 at 00:39
  • ==== > Try this first <======= https://stackoverflow.com/questions/36566236/npm-install-error-code-ebusy-errono-4082/45757541#45757541 – sijo vijayan Aug 18 '17 at 13:14