Gulp: Sometimes gulp del cause EPERM error

Created on 22 Oct 2014  路  9Comments  路  Source: gulpjs/gulp

Hi.

I'm trying del in my clean task.

gulp.task('clean', function(cb) {
 del('build/**', cb);
});

gulp.task('build', ['clean'], function() {
    ...
});

And from time to time during running build task I've got

'clean' errored after 24 ms
Error: EPERM, rmdir 'D:\dev\projects...

OS: Windows 7.

Is it problem of my implementation or just wrong behavior on Windows?

Sorry if it's not a good place to post this problem.

Thanks

Most helpful comment

Hmm. build/**/* also causes EPERM. Only build/**/*.* works without problem.

All 9 comments

EPERM means it doesn't have permission to delete the folder. You probably have the wrong permission set on that folder.

@sindresorhus, yeah, I understand, what means EPERM, but it happens only from time to time.

E.g. I run
1) gulp build
result correct (starting clean, finished clean)
...
trying again
n) gulp build
and got "starting clean EPERM error".
n+1) gulp build
correct

Could it be a problem of pattern?

'build/**'

Generally this happens on Windows because a virus scanner or other background service has the file open when you try to delete it. Thanks, MS -- a completely non-deterministic symptom. Are you on Windows?

@robich, Yes, I'm on windows. I'll try to disable antivirus but changing pattern from build/** to build solves problem. I suppose, that the problem can be in pattern. But my main suggestion is that del tries to remove folder during deliting file inside this folder. Is it possible?

Hmm. build/**/* also causes EPERM. Only build/**/*.* works without problem.

Could anyone explain, how to handle this type of errors? e.g. to repeat task with del() in case of error

I'm not sure if it's related directly to your problem but I was also getting this error intermittently - although checking my files & folders, the task had successfully run.

Looking at your particular use case it doesn't seem like this applies but I hope this helps others:

First, I was also getting another issue with watch on my build picking up newly created files:
https://github.com/floatdrop/gulp-watch/issues/1

After finding this solution and solving the problem above, my del issue disappeared too:

Basically when my globs started with ./ it caused this error - simply remove it so:

./scripts/**

would become:

scripts/**

(I'm on Windows 8)

Was this page helpful?
0 / 5 - 0 ratings