1

New to Gulp. My default task is using the pluginrun-sequence which tells task deleteBuild to run, then makeBuild.

Randomly, I am getting an ENOENT error which seems to be telling me that I'm either referencing files that don't exist for deletion or copy. My tasks are:

deleteBuild:

gulp.task('deleteBuild', function(done) {
  var del = require('del');
  del(['build/**/*'], done);
});

makeBuild:

gulp.task('makeBuild', function() {
  var stream = gulp.src(['src/**/*'], { base: 'src/' })
    .pipe(gulp.dest('build/');
});

Can someone inform me as to how to best address this issue? I'm hoping to seek a low-level understanding rather than to be shown a solution w/o an explanation. Thanks.

Aside: I tried the deleteBuild without a callback function as well, under the assumption that, as is, it would perform the deletion and only continue to the next task once it is complete, though this doesn't seem to be what is happening.

Aaron Martone
  • 61
  • 1
  • 6
  • Possible duplicate of [npm del error in gulpfile Visual Studio 2015](http://stackoverflow.com/questions/32743422/npm-del-error-in-gulpfile-visual-studio-2015) – kombucha Oct 02 '15 at 17:20
  • So they're saying del() doesn't support callbacks? Correct me if I'm wrong, but if it returns Promises (something I'm not too solid on), then I need to add a 'return' to the del() plugin call so that Gulp only continues to the next task once that Promise is fulfilled? – Aaron Martone Oct 02 '15 at 17:42
  • It used to support callbacks, but it doesn't anymore. That's why there's so many snippets on the web showing it used with a callback... And yep you can just return it and the task will end correctly :). – kombucha Oct 02 '15 at 18:17
  • Possible duplicate of [\`yo angular\` gives error: npm ERR! code ENOENT npm ERR! errno 34 (yes I have cleaned the cache and set .npmignore)](http://stackoverflow.com/questions/21964874/yo-angular-gives-error-npm-err-code-enoent-npm-err-errno-34-yes-i-have-cle) – Paul Sweatte Oct 02 '15 at 18:45

1 Answers1

0

That's probably because the deleteBuild does not return a gulp stream and thus leave the pipe broken. I would propose the following:

gulp.task('deleteBuild', function() {
  var del = require('del');
  var vinylPaths = require('vinyl-paths');

  return gulp.src(['build']) // no need for glob, just delete the build directory
    .pipe(vinylPaths(del));
});

gulp.task('makeBuild', function() {
  var stream = gulp.src(['src/**/*'], { base: 'src/' })
    .pipe(gulp.dest('build/');
});

gulp.task('default', function(cb) {
  var runSequence = require('run-sequence');

  runSequence('deleteBuild', ['makeBuild'], cb);
});

These tasks will first delete the build directory before executing the makeBuild task.

You'll need to install one additional plugin:

npm install vinyl-paths

For a ready to use example, please take a look a the gulpfile of skeletonSPA. This works for me ;-)

Elger van Boxtel
  • 1,030
  • 12
  • 23