gpt4 book ai didi

gulp 任务因 EEXIST 错误而失败

转载 作者:行者123 更新时间:2023-12-03 09:28:38 24 4
gpt4 key购买 nike

今天早上,我的 gulp 构建脚本开始失败;除了在项目目录中进行正常工作外,我没有对系统进行任何其他更改。

我有一个/src 目录,其中包含各种 HTML 片段、图像、javascript、LESS,我正在使用 gulp 编译/连接/复制它们并将它们放在/web 目录中。 'default' 任务运行一个 'build' 任务,它调用所有其他任务,然后设置 gulp.watch 来观察目录的变化,并运行适当的任务发现变化。

在每个任务开始时,我使用 del() 来清理目标文件夹。但是,当需要将内容放入目标文件夹时,任务失败并显示“EEXIST”错误,或者任务正常完成,并且某些文件从输出目录中随机丢失。

这是我的命令提示符,它显示随机失败的任务:

> user$ gulp
[11:58:02] Using gulpfile PROJECTPATH/gulpfile.js
[11:58:02] Starting 'styles'...
[11:58:02] Starting 'scripts'...
[11:58:02] Starting 'images'...
[11:58:02] Starting 'fonts'...
[11:58:02] Starting 'html'...
[11:58:03] Finished 'styles' after 726 ms
[11:58:03] gulp-imagemin: Minified 1 image (saved 7.38 kB - 10.4%)
[11:58:03] Finished 'fonts' after 714 ms
[11:58:03] Finished 'images' after 722 ms
[11:58:03] Finished 'scripts' after 741 ms
[11:58:03] Finished 'html' after 737 ms
[11:58:03] Starting 'build'...
[11:58:03] Finished 'build' after 9.61 μs
[11:58:03] Starting 'default'...
[11:58:03] Finished 'default' after 125 ms
> user$ gulp
[11:58:22] Using gulpfile PROJECTPATH/gulpfile.js
[11:58:22] Starting 'styles'...
[11:58:22] Starting 'scripts'...
[11:58:22] Starting 'images'...
[11:58:22] Starting 'fonts'...
[11:58:22] Starting 'html'...
[11:58:22] 'scripts' errored after 86 ms
[11:58:22] Error: EEXIST, mkdir 'PROJECTPATH/web/project_files/js'
[11:58:22] 'fonts' errored after 74 ms
[11:58:22] Error: ENOENT, open 'PROJECTPATH/web/project_files/fonts/glyphicons-halflings-regular.eot'
[11:58:23] 'html' errored after 144 ms
[11:58:23] Error: EEXIST, mkdir 'PROJECTPATH/web/project_files/templates/instruction'
[11:58:23] Finished 'styles' after 728 ms
[11:58:23] gulp-imagemin: Minified 1 image (saved 7.38 kB - 10.4%)
[11:58:23] Finished 'images' after 736 ms
> user$ gulp
[11:58:28] Using gulpfile PROJECTPATH/gulpfile.js
[11:58:28] Starting 'styles'...
[11:58:28] Starting 'scripts'...
[11:58:28] Starting 'images'...
[11:58:28] Starting 'fonts'...
[11:58:28] Starting 'html'...
[11:58:28] Finished 'styles' after 729 ms
[11:58:28] Finished 'fonts' after 707 ms
[11:58:28] Finished 'scripts' after 737 ms
[11:58:28] gulp-imagemin: Minified 1 image (saved 7.38 kB - 10.4%)
[11:58:28] Finished 'images' after 733 ms
[11:58:28] Finished 'html' after 740 ms
[11:58:28] Starting 'build'...
[11:58:28] Finished 'build' after 9.73 μs
[11:58:28] Starting 'default'...
[11:58:28] Finished 'default' after 120 ms
> user$ gulp
[11:58:34] Using gulpfile PROJECTPATH/gulpfile.js
[11:58:34] Starting 'styles'...
[11:58:34] Starting 'scripts'...
[11:58:34] Starting 'images'...
[11:58:34] Starting 'fonts'...
[11:58:34] Starting 'html'...
[11:58:34] 'scripts' errored after 95 ms
[11:58:34] Error: EEXIST, mkdir 'PROJECTPATH/web/project_files/js'
[11:58:34] 'fonts' errored after 84 ms
[11:58:34] Error: ENOENT, open 'PROJECTPATH/web/project_files/fonts/glyphicons-halflings-regular.eot'
[11:58:34] 'html' errored after 143 ms
[11:58:34] Error: EEXIST, mkdir 'PROJECTPATH/web/project_files/templates/instruction'
[11:58:35] Finished 'styles' after 737 ms
[11:58:35] gulp-imagemin: Minified 1 image (saved 7.38 kB - 10.4%)
[11:58:35] Finished 'images' after 742 ms

这是我正在使用的 gulp 文件:
var gulp = require('gulp'),
less = require('gulp-less'),
autoprefixer = require('gulp-autoprefixer'),
minifycss = require('gulp-minify-css'),
jshint = require('gulp-jshint'),
uglify = require('gulp-uglify'),
imagemin = require('gulp-imagemin'),
rename = require('gulp-rename'),
concat = require('gulp-concat'),
fileinclude = require('gulp-file-include'),
cache = require('gulp-cache'),
gutil = require('gulp-util'),
rename = require('gulp-rename'),
merge = require('merge-stream'),
del = require('del'),
libraries = [
'src/js/jquery-*.js',
'src/js/bootstrap/transition.js',
'src/js/bootstrap/collapse.js',
'src/js/bootstrap/modal.js',
'src/js/bootstrap/affix.js',
'src/js/bootstrap-datepicker.js',
'src/js/bootbox.js',
'src/js/chosen.jquery.js',
'src/js/underscore.js',
'src/js/sha1.js',
'src/js/DeviceIdConverter.js',
'src/js/custom.js'
],
ieLibraries = [
'src/js/html5shiv.js',
'src/js/respond.js'
],
appConfig = [
'src/js/country.json',
'src/js/locations.json',
'src/js/make_model.json',
'src/js/project.js'
];

gulp.task('styles', function() {
del(['web/project_files/css']);
return gulp.src('src/less/project.less')
.pipe(less())
.pipe(gulp.dest('web/project_files/css'))
});

gulp.task('scripts', function() {
del(['web/project_files/js']);

var libraryStream = gulp.src(libraries)
.pipe(concat('libraries.js')),

ieLibraryStream = gulp.src(ieLibraries)
.pipe(concat('ie8.js')),

appConfigStream = gulp.src(appConfig)
.pipe(rename(function(path) {
path.extname = '.js';
}));

return merge(libraryStream, ieLibraryStream, appConfigStream)
.pipe(gulp.dest('web/project_files/js'));
});

gulp.task('images', function() {
del(['web/project_files/img']);
return gulp.src('src/img/**/*.+(jpg|png)')
.pipe(imagemin({optimizationLevel: 3, progressive: true, interlaced: true }))
.pipe(gulp.dest('web/project_files/img'))
});

gulp.task('fonts', function() {
del(['web/project_files/fonts']);
return gulp.src('src/fonts/**/*.+(eot|svg|ttf|woff|otf)')
.pipe(rename(function(path) {
path.dirname = '';
}))
.pipe(gulp.dest('web/project_files/fonts'));
});

gulp.task('html', function() {
del(['web/project.htm']);
del(['web/project_files/templates']);

var htmlStream = gulp.src('src/html/index.html')
.pipe(fileinclude())
.pipe(rename('project.htm'));

var templateStream = gulp.src('src/html/templates/**/*.html')
.pipe(rename(function(path) {
path.dirname = "/project_files/templates/"+path.dirname;
path.extname = ".tpl";
}));

return(merge(htmlStream, templateStream))
.pipe(gulp.dest('web'));
});

gulp.task('build', ['styles', 'scripts', 'images', 'fonts', 'html'], function() {

});


gulp.task('default', ['build'], function() {
gulp.watch('src/html/**/*.html', ['html']);
gulp.watch('src/less/**/*.less', ['styles']);
gulp.watch('src/js/**/*.js', ['scripts']);
gulp.watch('src/img/**/*.+(jpg|png)', ['images']);
gulp.watch('src/fonts/**/*.+(eot|svg|ttf|woff|otf)', ['fonts']);
});

错误消息说目标位置存在,但 del() 不应该在每个子任务开始时删除目标目录吗?

更新:

这是我现在组织任务的方式,它似乎工作快速且正确:
gulp.task('scripts', function() {
del(['web/js'], function(err) {
if (err) return;
return gulp.src('src/js/**/*.js')
.pipe(concat('mything.js'))
.pipe(gulp.dest('web/js'));
});
});

最佳答案

shouldn't del() be removing the destination directory at the start of every child task?



是的,但是您最终会在 del 完成之前创建新事物(它是异步的)。

我会创建一个单独的任务并仅在进行完整构建时将其用作依赖项。
gulp.task('clean', function(cb) {
del(['something/**'], cb);
});

.. 或使用 del.sync
https://github.com/sindresorhus/del#delsyncpatterns-options

关于gulp 任务因 EEXIST 错误而失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26742777/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com