node.js - 运行任务时 Gulp 错误 : ENOENT, lstat

标签 node.js gulp web-frontend

我正在使用 gulp 复制和清理我的前端项目。我想运行一些顺序任务。这意味着,例如,我希望复制任务开始和完成,然后运行其以下任务(复制任务)。 我在运行任务时经常看到此错误:

events.js:72
    throw er; // Unhandled 'error' event
          ^
Error: ENOENT, lstat '/home/reza/projects/account-web/dist/views'

lstat 之后,我每次随机看到一个文件名。我只是发现,当没有 dist 文件夹或者它是空的时,复制任务可以正常运行,但是当 dist 文件夹不为空时,即使是 clean 任务也会抛出错误。 下面是我的 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'

最佳答案

我想知道它是否试图在嵌套文件夹已被删除后异步删除嵌套文件夹中的文件。尝试更改您的 src 以包含不带通配符的 dist 文件夹。这将告诉它删除 dist 文件夹而不是单独删除每个项目。

gulp.task('clean', function () {
    gulp.src('./dist').pipe(clean());
});

gulp-clean 似乎也已被弃用,您可能需要查看 del作为替代品。它能够正确处理您的原始 glob 模式。

关于node.js - 运行任务时 Gulp 错误 : ENOENT, lstat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31903057/

相关文章:

javascript - 如何将组件注入(inject)到Angular2中的div选择器中

node.js - 如何在 Node 中获取用户登录?

node.js - 是否可以使用 testcafe/node 模拟由单击按钮触发的函数的结果?

javascript - 为什么我不能在 node.js 中对这个 URL 进行 url 编码?

node.js - 使用不同的轨道关键字重新启动nodejs ntwitter twitter流

error-handling - gulp-notify-获取文件名,而不是整个路径,并显示错误

javascript - 使用 gulp 将 scss 转换为 css。 [问题]

CSS3 圆 Angular - 只有边框是圆的,内框仍然是方形的

javascript - 侧面导航栏在切换时更改页面内容的对齐方式

javascript - 如何将 gulp.watch() 传递给管道?