首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用TypeError -npm在流多任务时获取merge2中的-npm

使用TypeError -npm在流多任务时获取merge2中的-npm
EN

Stack Overflow用户
提问于 2018-05-30 08:28:14
回答 1查看 160关注 0票数 0

我正在使用merge2流多个图像优化任务。我正在使用merge2, gulp-imagemin, imagemin-pngquant, imagemin-mozjpeg, gulp-image-resize, gulp-webp

当我执行任务时,它按照我的要求完美地工作,但是我在终端中得到了TypeError:- TypeError: Cannot read property '_readableState' of undefined at pauseStreams。我在gulpfile中的代码如下所示:

代码语言:javascript
复制
gulp.task('mergeimg',function(){
 var bannerImages = [2000,1600,1200,800,533];

 var imgmin =  bannerImages.forEach(function(size){
    return gulp.src( '../html/assets/unoptimized/banners/**/*.{png,jpg,jpeg}')
    .pipe(imageResize({
       width: size,
       crop:true,
 }))
 .pipe(imagemin({
            progressive: true,
            use: [pngquant()],
        use:[imageminMozjpeg({quality:85})],

   }))
 .pipe(rename(function(path){
    path.basename += '_'+size
}))
 .pipe(debug())
   .pipe(gulp.dest('../html/assets/temp/' ))
 });
 var imgretina =   bannerretina.forEach(function(size){
  return gulp.src( '../html/assets/unoptimized/banners/**/*.{png,jpg,jpeg}')
   .pipe(imageResize({
      width: size * 2,
    crop:true,
 }))
 .pipe(imagemin({
        progressive: true,
        use: [pngquant()],
       use:[imageminMozjpeg({quality:85})],
}))
  .pipe(rename(function(path){
        path.basename += '_'+size+'@2x'
    }))
  .pipe(debug())
  .pipe(gulp.dest('../html/assets/temp/' ))
  });
var webPimg = bannerImages.forEach(function(size){
   return gulp.src( '../html/assets/unoptimized/banners/**/*.{png,jpg,jpeg}')
   .pipe(webp())
    .pipe(rename(function(path){
        path.basename += '_'+size
}))
  .pipe(debug())
  .pipe(gulp.dest('../html/assets/temp/' ))
 });
  var mergedStream = merge( imgmin, imgretina, webPimg );
 return mergedStream;
});

我的错误代码如下:

代码语言:javascript
复制
[13:26:00] Starting 'mergeimg'...
[13:26:00] 'mergeimg' errored after 28 ms
[13:26:00] TypeError: Cannot read property '_readableState' of undefined
    at pauseStreams (E:\xamp\htdocs\damithemes\capture-kids\gulp_automation\node
_modules\merge2\index.js:98:18)
    at addStream (E:\xamp\htdocs\damithemes\capture-kids\gulp_automation\node_mo
dules\merge2\index.js:31:25)
    at merge2 (E:\xamp\htdocs\damithemes\capture-kids\gulp_automation\node_modul
es\merge2\index.js:90:30)
    at Gulp.<anonymous> (E:\xamp\htdocs\damithemes\capture-kids\gulp_automation\
gulpfile.js:183:24)
    at module.exports (E:\xamp\htdocs\damithemes\capture-kids\gulp_automation\no
de_modules\orchestrator\lib\runTask.js:34:7)
    at Gulp.Orchestrator._runTask (E:\xamp\htdocs\damithemes\capture-kids\gulp_a
utomation\node_modules\orchestrator\index.js:273:3)
    at Gulp.Orchestrator._runStep (E:\xamp\htdocs\damithemes\capture-kids\gulp_a
utomation\node_modules\orchestrator\index.js:214:10)
    at Gulp.Orchestrator.start (E:\xamp\htdocs\damithemes\capture-kids\gulp_auto
mation\node_modules\orchestrator\index.js:134:8)
    at C:\Users\Da mirecle\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:129
:20
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
[13:26:01] gulp-debug: ..\html\assets\unoptimized\banners\child-with-bags_533.we
bp
[13:26:01] gulp-debug: 1 item
[13:26:01] gulp-debug: ..\html\assets\unoptimized\banners\child-with-bags_2000.w
ebp
[13:26:01] gulp-debug: 1 item
[13:26:01] gulp-debug: ..\html\assets\unoptimized\banners\child-with-bags_1200.w
ebp
[13:26:01] gulp-debug: 1 item
[13:26:01] gulp-debug: ..\html\assets\unoptimized\banners\child-with-bags_800.we
bp
[13:26:01] gulp-debug: 1 item
[13:26:01] gulp-debug: ..\html\assets\unoptimized\banners\child-with-bags_1600.w
ebp
[13:26:01] gulp-debug: 1 item
[13:26:02] gulp-debug: ..\html\assets\unoptimized\banners\child-with-bags_800.jp
g
[13:26:02] gulp-imagemin: Minified 1 image (saved 858 B - 2%)
[13:26:02] gulp-debug: 1 item
[13:26:02] gulp-debug: ..\html\assets\unoptimized\banners\child-with-bags_1200.j
pg
[13:26:02] gulp-imagemin: Minified 1 image (saved 858 B - 1.4%)
[13:26:02] gulp-debug: 1 item
[13:26:02] gulp-debug: ..\html\assets\unoptimized\banners\child-with-bags_533@2x
.jpg
[13:26:02] gulp-imagemin: Minified 1 image (saved 858 B - 1.6%)
[13:26:02] gulp-debug: 1 item
[13:26:02] gulp-debug: ..\html\assets\unoptimized\banners\child-with-bags_533.jp
g
[13:26:02] gulp-imagemin: Minified 1 image (saved 858 B - 3.1%)
[13:26:02] gulp-debug: 1 item
[13:26:02] gulp-debug: ..\html\assets\unoptimized\banners\child-with-bags_1600.j
pg
[13:26:02] gulp-imagemin: Minified 1 image (saved 858 B - 1.1%)
[13:26:02] gulp-debug: 1 item
[13:26:02] gulp-debug: ..\html\assets\unoptimized\banners\child-with-bags_2000@2
x.jpg
[13:26:02] gulp-imagemin: Minified 1 image (saved 858 B - 1.1%)
[13:26:02] gulp-debug: 1 item
[13:26:02] gulp-debug: ..\html\assets\unoptimized\banners\child-with-bags_800@2x
.jpg
[13:26:02] gulp-imagemin: Minified 1 image (saved 858 B - 1.1%)
[13:26:02] gulp-debug: 1 item
[13:26:02] gulp-debug: ..\html\assets\unoptimized\banners\child-with-bags_1200@2
x.jpg
[13:26:02] gulp-imagemin: Minified 1 image (saved 858 B - 1.1%)
[13:26:02] gulp-debug: 1 item
[13:26:02] gulp-debug: ..\html\assets\unoptimized\banners\child-with-bags_2000.j
pg
[13:26:02] gulp-imagemin: Minified 1 image (saved 858 B - 1.1%)
[13:26:02] gulp-debug: 1 item
[13:26:02] gulp-debug: ..\html\assets\unoptimized\banners\child-with-bags_1600@2
x.jpg
[13:26:02] gulp-imagemin: Minified 1 image (saved 858 B - 1.1%)
[13:26:02] gulp-debug: 1 item

从代码中可以看出,所有的图像都在压缩和转换成我想要的webp格式,但是我真的锁定了错误代码开始的原因。我猜,我的forEach循环是不对的。希望不是这样的。我不知道到底出了什么问题。有谁能帮我弄清楚。提前谢谢。

我本可以使用吞咽反应来实现这一点,但是由于我有32位Windows,所以锐利依赖项无法工作。在这种情况下,我必须坚持的吞咽图像调整过程。

EN

回答 1

Stack Overflow用户

发布于 2018-05-31 07:05:26

这个问题已经解决了。实际上,我在使用forEach()而不是.map()时出了问题。当我在那里长大时,我得到了merge2 Github问题的帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50599867

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档