I am using gulp to copy and clean my front-end projects. I want to run some sequential tasks. It means, for example, I want the copy task to be started and finished and then run its the following task (a copy task). I frequently see this error when I run my tasks:
events.js:72
throw er; // Unhandled 'error' event
^
Error: ENOENT, lstat '/home/reza/projects/account-web/dist/views'
After lstat
, each I see a file name randomly. I just find that when there is no dist folder or it is empty copy tasks run properly but when the dist folder is not empty even clean task throws and error.
There are my gulp file and command results below:
var gulp = require('gulp');
var clean = require('gulp-clean');
var merge = require('gulp-merge');
var runSequence = require('run-sequence');
gulp.task('clean', function () {
gulp.src('./dist/**').pipe(clean());
});
gulp.task('copy-js', function () {
return gulp.src('app/js/**').pipe(gulp.dest('dist/js/'));
});
gulp.task('copy-bower', function () {
return gulp.src('bower_components/**').pipe(gulp.dest('dist/bower_components/'));
});
gulp.task('copy-script', function () {
return gulp.src('app/scripts/**').pipe(gulp.dest('dist/scripts/'));
});
gulp.task('copy-styles', function () {
var stream1 = gulp.src('app/styles/**').pipe(gulp.dest('dist/styles/'));
var stream2 = gulp.src('app/fonts/**').pipe(gulp.dest('dist/fonts/'));
var stream3 = gulp.src('app/img/**').pipe(gulp.dest('dist/img/'));
return merge(stream1, stream2, stream3);
});
gulp.task('copy-views', function () {
var stream1 = gulp.src('app/views/**').pipe(gulp.dest('dist/views/'));
var stream2 = gulp.src('app/*').pipe(gulp.dest('dist/'));
return merge(stream1, stream2);
});
gulp.task('dist', function () {
runSequence(['copy-bower','copy-js', 'copy-script', 'copy-styles', 'copy-views']);//
});
gulp.task('dev', function () {
runSequence('clean', 'dist')
});
gulp.task('default', ['dev']);
I thought that there is concurrency problem and the tasks are not running really sequentially, so I tries some modules to solve this problem like runSequence.
➜ account-web git:(master) ✗ gulp clean
[14:20:55] Using gulpfile ~/projects/account-web/Gulpfile.js
[14:20:55] Starting 'clean'...
[14:20:55] Finished 'clean' after 5.58 ms
events.js:72
throw er; // Unhandled 'error' event
^
Error: ENOENT, lstat '/home/reza/projects/account-web/dist/views'
➜ account-web git:(master) ✗ gulp dev
[14:35:03] Using gulpfile ~/projects/account-web/Gulpfile.js
[14:35:03] Starting 'dev'...
[14:35:03] Starting 'clean'...
[14:35:03] Finished 'clean' after 5.47 ms
[14:35:03] Starting 'dist'...
[14:35:03] Starting 'copy-bower'...
[14:35:03] Starting 'copy-js'...
[14:35:03] Starting 'copy-script'...
[14:35:03] Starting 'copy-styles'...
[14:35:03] Starting 'copy-views'...
[14:35:03] Finished 'dist' after 14 ms
[14:35:03] Finished 'dev' after 22 ms
stream.js:94
throw er; // Unhandled stream error in pipe.
^
Error: ENOENT, open '/home/reza/projects/account- web/dist/styles/fonts.css'