peter-vilja / gulp-clean

A gulp plugin for removing files and folders from given paths.
177 stars 21 forks source link

unhandled 'error' event #7

Closed fraserxu closed 10 years ago

fraserxu commented 10 years ago

I got this error while running gulp clean task.

// Clean.
gulp.task('clean', function() {
    gulp.src(['client/dist'], {read: false}).pipe(clean());
});
events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: Unable to delete "/Users/fraserxu/work/Octokan/client/dist" file (ENOTEMPTY, rmdir '/Users/fraserxu/work/Octokan/client/dist/assets/fonts').
    at /Users/fraserxu/work/Octokan/node_modules/gulp-clean/index.js:20:21
    at CB (/Users/fraserxu/work/Octokan/node_modules/gulp-clean/node_modules/rimraf/rimraf.js:42:5)
    at /Users/fraserxu/work/Octokan/node_modules/gulp-clean/node_modules/rimraf/rimraf.js:135:18
    at CB (/Users/fraserxu/work/Octokan/node_modules/gulp-clean/node_modules/rimraf/rimraf.js:42:5)
    at /Users/fraserxu/work/Octokan/node_modules/gulp-clean/node_modules/rimraf/rimraf.js:135:18
    at CB (/Users/fraserxu/work/Octokan/node_modules/gulp-clean/node_modules/rimraf/rimraf.js:42:5)
    at Object.oncomplete (fs.js:107:15)
vatula commented 10 years ago

I have a similar

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: watch EPERM
    at errnoException (fs.js:1019:11)
    at FSEvent.FSWatcher._handle.onchange (fs.js:1037:26)
ddarbyson commented 10 years ago

Yup, same issue here. I can work around it by prepending 'return' on the gulp object like so

gulp.task('clean', function() {
  return gulp.src(['my_build_path'], {read: false})
    .pipe(clean({force: true}));
});

not sure why this fixes the problem though...

iambrandonn commented 10 years ago

I'm guessing this is caused by the asynchronous removal of the files, and you have other tasks which are writing files into the directory before it finishes being deleted. One of Gulp's documented ways of handling asynchronous tasks is to return the stream from the function. See https://github.com/gulpjs/gulp/blob/master/docs/API.md#return-a-stream

I believe that is why it works for you @ddarbyson.

FrankFang commented 10 years ago

@iambrandonn Agreed and thanks

ddarbyson commented 10 years ago

Thanks, you are correct @iambrandonn

Feel free to close the ticket...

konsumer commented 9 years ago

I get this error, and all my gulp tasks return their streams:

var gulp = require('gulp-help')(require('gulp')),
  uglify = require('gulp-uglify'),
  imagemin = require('gulp-imagemin'),
  browserify = require('browserify'),
  reactify = require('reactify'),
  less = require('gulp-less'), 
  clean = require('gulp-clean'),
  streamify = require('gulp-streamify'),
  source = require('vinyl-source-stream'),
  LessPluginCleanCSS = require("less-plugin-clean-css"),
  LessPluginAutoPrefix = require('less-plugin-autoprefix'),
  cleancss = new LessPluginCleanCSS({advanced: true}),
  autoprefix = new LessPluginAutoPrefix({browsers: ["last 2 versions"]});

gulp.task('clean', 'delete built files', function() {
  return gulp.src('./build', {read: false})
    .pipe(clean());
});

gulp.task('build:js', 'build & minify just application javascript', function(){
  return browserify('./src/jsx/index.jsx')
    .transform(reactify)
    .bundle()
    .pipe(source('app.js'))
    .pipe(streamify(uglify()))
    .pipe(gulp.dest('./build/app'));
});

gulp.task('build:css', 'build & minify just application CSS', function(){
  return gulp.src('./src/less/app.less')
    .pipe(less({paths: ['./src/less'], plugins: [autoprefix, cleancss]}))
    .pipe(gulp.dest('./build/app'));
});

gulp.task('build:img', 'optimize images', function(){
  return gulp.src('./src/images/**/*')
    .pipe(imagemin({}))
    .pipe(gulp.dest('./build/app/images'));
});

// just build, don't minify
gulp.task('build:js:dev', false, function(){
  return browserify('./src/jsx/index.jsx')
    .transform(reactify)
    .bundle()
    .pipe(source('app.js'))
    .pipe(gulp.dest('./build/app'));
});

// just build, don't minify & clean
gulp.task('build:css:dev', false, function(){
  return gulp.src('./src/less/app.less')
    .pipe(less({paths: ['./src/less'], plugins: [autoprefix]}))
    .pipe(gulp.dest('./build/app'));
});

// copy static assets
gulp.task('copy:static', false, function(){
  return gulp.src('./src/static/**/*')
    .pipe(gulp.dest('./build/app'));
});

gulp.task('build', 'build application CSS & javascript for production', ['clean', 'copy:static', 'build:img', 'build:css','build:js']);

gulp.task('watch', 'watch for changes, for development', ['clean', 'copy:static', 'build:img', 'build:css:dev','build:js:dev'], function(){
  gulp.watch('./src/jsx/**/*.jsx', ['build:js:dev']);
  gulp.watch('./src/less/**/*.less', ['build:css:dev']);
  gulp.watch('./src/static/**/*', ['copy:static']);
  gulp.watch('./src/images/**/*', ['build:img']);
});

It works fine with gulp clean but not gulp build. Also, no error if I do gulp clean && gulp build.

sekoyo commented 9 years ago

I get the same issue too even when returning the stream, I get it with all the gulp clean type plugins I have tried actually, but not with any grunt ones

dwelch2344 commented 9 years ago

+1 to getting this suddenly. Maybe a change in the way gulp operates?

dimatter commented 8 years ago

bump