【发布时间】:2015-09-16 21:55:38
【问题描述】:
我正在使用 gulp 来复制和清理我的前端项目。我想运行一些顺序任务。这意味着,例如,我希望启动和完成复制任务,然后运行它的以下任务(复制任务)。 我在运行任务时经常看到这个错误:
events.js:72
throw er; // Unhandled 'error' event
^
Error: ENOENT, lstat '/home/reza/projects/account-web/dist/views'
lstat之后,每一个我随机看到一个文件名。我只是发现当没有 dist 文件夹或者它是空的复制任务时,复制任务可以正常运行,但是当 dist 文件夹不为空时,即使是清理任务也会抛出错误。
下面是我的 gulp 文件和命令结果:
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。
➜ 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'
【问题讨论】:
-
@Avalanche 他的问题是“生成 ENOENT”,但我的问题是“错误:ENOENT,打开”
-
hmm... 在我看来,您仍然没有处理一些错误。根据documentation,Lstat 似乎是一个异步操作——这可能会导致一些麻烦。
-
@Avalanche 但是你为什么要提高 lstat?这是一种避免错误的方法吗?我只是按照帖子中关于错误处理的说明进行操作,但我仍然看到同样的错误!
-
我不记得有这样的问题,但看起来你的 gulp conf 在编译文件时出现了一些错误;这就是为什么您的 dist 文件夹为空或不存在的原因。
标签: node.js gulp web-frontend