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

error thrown when trying to delete a file that is gone. #26

Open
bcowgill opened this issue Apr 19, 2017 · 4 comments
Open

error thrown when trying to delete a file that is gone. #26

bcowgill opened this issue Apr 19, 2017 · 4 comments

Comments

@bcowgill
Copy link

gulp-clean gets the listing of files to delete:

build/x
build/x/this.js

it seems the deletion of build/x gets rid of everything and when clean tries to delete build/x/this.js it gives an error. WHY? it's already gone! Perhaps clean should sort the list in reverse length order before doing its work or have an option to ignore / warn on files that are missing.

@bcowgill
Copy link
Author

note, was using 'build/**/*' as the match pattern. switching to just 'build' solves the immediate problem.

@nullbio
Copy link

nullbio commented Apr 20, 2017

I have a related problem -- I'm using Gulp 4, I'm trying to call delete on a directory that may or may not be present, and I'm getting:

[15:13:00] Error: File not found with singular glob: /home/pat/gop/src/github.com/nullbio/lolwtf/dist/public/assets/
    at Glob.<anonymous> (/home/pat/gop/src/github.com/nullbio/lolwtf/node_modules/glob-stream/index.js:41:11)
    at Glob.g (events.js:291:16)
    at emitOne (events.js:96:13)
    at Glob.emit (events.js:188:7)
    at Glob._finish (/home/pat/gop/src/github.com/nullbio/lolwtf/node_modules/glob/glob.js:172:8)
    at done (/home/pat/gop/src/github.com/nullbio/lolwtf/node_modules/glob/glob.js:159:12)
    at Glob._processSimple2 (/home/pat/gop/src/github.com/nullbio/lolwtf/node_modules/glob/glob.js:652:12)
    at /home/pat/gop/src/github.com/nullbio/lolwtf/node_modules/glob/glob.js:640:10
    at Glob._stat2 (/home/pat/gop/src/github.com/nullbio/lolwtf/node_modules/glob/glob.js:736:12)
    at lstatcb_ (/home/pat/gop/src/github.com/nullbio/lolwtf/node_modules/glob/glob.js:728:12)

The dist folder in my glob there that you can see (and naturally all of its subfolders) have the potential of not being created yet.

Is there some way I can ignore the error message, or prevent it from happening? I tried on('error'), but that doesn't seem to get fired.

@peter-vilja
Copy link
Owner

It's been a while since I have touched this, but as quite a few are clearly still using gulp-clean, I'll try to be more active.

it seems the deletion of build/x gets rid of everything and when clean tries to delete build/x/this.js it gives an error.

@bcowgill I created a similar case as yours:

'use strict';
const gulp = require('gulp');
const clean = require('gulp-clean');

gulp.task('clean', () => {
  return gulp.src('build/**/*')
    .pipe(clean());
});

I can confirm that filepaths gulp-clean receives are the ones you mentioned:

  • build/x
  • build/x/this.js

But in my case the cleaning works and gulp-clean does not emit errors:

$ node -v
v9.3.0
$ gulp -v
[21:29:52] CLI version 2.0.0
[21:29:52] Local version 4.0.0
$ gulp clean
[21:29:56] Using gulpfile ~/gulpfile.js
[21:29:56] Starting 'clean'...
[21:29:56] Finished 'clean' after 45 ms

Why it actually works, is because of rimraf handles ENOENT errors behind the scenes and returns successfully. Thus even when gulp-clean tries to remove a file which does not exist anymore everything should work nicely. See the rimraf README.

@bcowgill can you provide a reproducible example of your problem? Thanks.

@nullbio I am not sure your case actually relates to gulp-clean as gulp-clean does not try to find files with a glob. Most likely this happens already before the execution comes to the gulp-clean plugin. But to be sure could you provide more details or a simplified example where your error occurs? Thanks.

@selim13
Copy link

selim13 commented Oct 3, 2018

I know that this is kinda old thread, but for those who are facing @nullbio problem with gulp 4:
passing allowEmpty: true to gulp.src should solve the problem.

gulp.task("clean", function() {
	return gulp.src("./dist", { read: false, allowEmpty: true })
		.pipe(gulpClean());
});

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

4 participants