2017-02-06 18 views
1

私はAngular JSベースのアプリケーションで作業しています。私は、JSコードからコメントを醜くする/削除するための一連のgulpコマンドを書いています。私は例外を適切にトレースしたいので、タスクを「ポンプ」(コードを参照してください)で包み込み、パワーシェルを通して「ポンプ」をインストールしました。 最後にgulpコマンドを実行しようとすると、このエラーが表示されます。私はこれでグーグルで動かなかった。助けてください。なぜTypeError:stream.onは関数ではありません

Gulpfile

// include plug-ins 
'use strict'; 
var gulp = require('gulp'); 
var concat = require('gulp-concat'); 
var htmlbuild = require('gulp-htmlbuild'); 
var plugins = require('gulp-load-plugins')(); 
var es = require('event-stream'); 
var clean = require('gulp-clean'); 
var uglify = require('gulp-uglify'); 
var strip = require('gulp-strip-comments'); 
var pump = require('pump'); 

// pipe a glob stream into this and receive a gulp file stream 
var gulpSrc = function (opts) { 
    var paths = es.through(); 
    var files = es.through(); 
    paths.pipe(es.writeArray(function (err, srcs) { 
     var fixedFiles = []; 
     for (var i=0; i < srcs.length; i++) 
     { 
      fixedFiles[i] = srcs[i].replace("~", "."); 
      console.log(fixedFiles[i]); 
     } 
     gulp.src(fixedFiles, opts).pipe(files); 
    })); 

    return es.duplex(paths, files); 
}; 

var jsBuild = es.pipeline(
    plugins.concat('all.js'), 
    gulp.dest('./Scripts/') 
); 

gulp.task('clean', function() { 
    return pump(gulp.src('./Scripts/all.js') 
      .pipe(clean({ force: true }))); 
}); 

gulp.task('build', function() { 
    return pump(gulp.src(['./Views/Home/Layout.cshtml']) 
    .pipe(htmlbuild({ 
     js: htmlbuild.preprocess.js(function (block) { 
      block.pipe(gulpSrc()) 
      .pipe(jsBuild); 
     }) 
    })) 
    ); 
}); 

// Minify 
gulp.task('minify', function() { 
    return pump (gulp.src(['./Scripts/all.js']). 
    pipe(uglify()). 
    pipe(gulp.dest('./testing'))); 
}); 

// Strip Comments 
gulp.task('StripComments', function() { 
    return pump(gulp.src(['./Scripts/all.js']) 
     .pipe(strip()) 
     .pipe(gulp.dest('./testing'))); 
}); 

gulp.task(pump('default', ['clean', 'build', 'StripComments'], function() { })); 

パワーシェル

PS C:\dev.net14\DevelopmentPhase2\MyCompany.WebMain> gulp 
C:\dev.net14\DevelopmentPhase2\MyCompany.WebMain\node_modules\pump\index.js:24 
    stream.on('close', function() { 
     ^

TypeError: stream.on is not a function 
    at destroyer (C:\dev.net14\DevelopmentPhase2\MyCompany.WebMain\node_modules\pump\index.js:24:10) 
    at C:\dev.net14\DevelopmentPhase2\MyCompany.WebMain\node_modules\pump\index.js:68:12 
    at Array.map (native) 
    at pump (C:\dev.net14\DevelopmentPhase2\MyCompany.WebMain\node_modules\pump\index.js:65:26) 
    at Object.<anonymous> (C:\dev.net14\DevelopmentPhase2\MyCompany.WebMain\gulpfile.js:66:11) 
    at Module._compile (module.js:570:32) 
    at Object.Module._extensions..js (module.js:579:10) 
    at Module.load (module.js:487:32) 
    at tryModuleLoad (module.js:446:12) 
    at Function.Module._load (module.js:438:3) 

C:\ dev.net14 \ DevelopmentPhase2 \ MyCompany.WebMain \ node_modules \ポンプ\

index.js
var once = require('once') 
var eos = require('end-of-stream') 
var fs = require('fs') // we only need fs to get the ReadStream and WriteStream prototypes 

var noop = function() {} 

var isFn = function (fn) { 
    return typeof fn === 'function' 
} 

var isFS = function (stream) { 
    if (!fs) return false // browser 
    return (stream instanceof (fs.ReadStream || noop) || stream instanceof (fs.WriteStream || noop)) && isFn(stream.close) 
} 

var isRequest = function (stream) { 
    return stream.setHeader && isFn(stream.abort) 
} 

var destroyer = function (stream, reading, writing, callback) { 
    callback = once(callback) 

    var closed = false 
    stream.on('close', function() { 
    closed = true 
    }) 

    eos(stream, {readable: reading, writable: writing}, function (err) { 
    if (err) return callback(err) 
    closed = true 
    callback() 
    }) 

    var destroyed = false 
    return function (err) { 
    if (closed) return 
    if (destroyed) return 
    destroyed = true 

    if (isFS(stream)) return stream.close() // use close for fs streams to avoid fd leaks 
    if (isRequest(stream)) return stream.abort() // request.destroy just do .end - .abort is what we want 

    if (isFn(stream.destroy)) return stream.destroy() 

    callback(err || new Error('stream was destroyed')) 
    } 
} 

var call = function (fn) { 
    fn() 
} 

var pipe = function (from, to) { 
    return from.pipe(to) 
} 

var pump = function() { 
    var streams = Array.prototype.slice.call(arguments) 
    var callback = isFn(streams[streams.length - 1] || noop) && streams.pop() || noop 

    if (Array.isArray(streams[0])) streams = streams[0] 
    if (streams.length < 2) throw new Error('pump requires two streams per minimum') 

    var error 
    var destroys = streams.map(function (stream, i) { 
    var reading = i < streams.length - 1 
    var writing = i > 0 
    return destroyer(stream, reading, writing, function (err) { 
     if (!error) error = err 
     if (err) destroys.forEach(call) 
     if (reading) return 
     destroys.forEach(call) 
     callback(error) 
    }) 
    }) 

    return streams.reduce(pipe) 
} 

module.exports = pump 

答えて

0

あなたは、このようにストリームを定義する必要があります。

var stream= fs.readStream('filename'); 

私はこのような流れを定義することを好む:

var stream= fs.createReadStream('filename'); 
関連する問題