I got an error TypeError: The "streams[stream.length - 1]" property must be of type function. Received an instance of Pumpify while trying to minify a javascript using gulp package ,
Using gulpfile MY_PROJECT_PATH\gulpfile.js
Starting 'compress'...
'compress' errored after 21 ms
TypeError: The "streams[stream.length - 1]" property must be of type function. Received an instance of Pumpify
at popCallback (MY_PROJECT_PATH\node_modules\readable-stream\lib\internal\streams\pipeline.js:59:3)
at pipeline (MY_PROJECT_PATH\node_modules\readable-stream\lib\internal\streams\pipeline.js:134:37
This is my code in [gulpfile.js]
var gulp = require('gulp');
var uglify = require('gulp-uglify');
var pipeline = require('readable-stream').pipeline;
gulp.task('compress', function () {
return pipeline(
gulp.src('DIR_NAME/*.js'),
uglify(),
gulp.dest('DIR_NAME/dist')
);
});
The package.json file: I tried to install [pipeline, readable-stream, pumpify] while debugging
{
"devDependencies": {
"gulp": "^4.0.2",
"gulp-uglify": "^3.0.2",
"pipeline": "^0.1.3",
"pumpify": "^2.0.1",
"readable-stream": "^4.3.0"
}
}
Solution 1
The
pipelinefunction fromstreamorreadable_streamexpects a callback as a last parameter.Solution 2
stream/promisesexposes a promise-based version ofpipelinewhich does not use a callback:Solution 3
Then there is the tradition way of piping steams, with the
.pipe()method.