Gulp Error: ENOENT, lstat while running tasks
我正在使用gulp复制和清理前端项目。我想运行一些顺序的任务。例如,这意味着我希望开始并完成复制任务,然后运行其以下任务(复制任务)。
运行任务时,我经常会看到此错误:
1 2 3 4 | events.js:72 throw er; // Unhandled 'error' event ^ Error: ENOENT, lstat '/home/reza/projects/account-web/dist/views' |
在
以下是我的gulp文件和命令结果:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | 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']); |
我认为存在并发问题,并且任务没有按顺序运行,因此我尝试使用一些模块来解决此问题,例如runSequence。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | ? 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' |
我想知道在嵌套文件夹已被删除之后,是否正在尝试异步删除嵌套文件夹中的文件。尝试将您的src更改为不包含通配符的dist文件夹。这将告诉它删除dist文件夹而不是单独删除每个项目。
1 2 3 | gulp.task('clean', function () { gulp.src('./dist').pipe(clean()); }); |
似乎也已不推荐使用gulp-clean,您可能想签出del作为替代品。它能够正确处理您的原始glob模式。