Reputation: 632
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"
}
}
Upvotes: 3
Views: 1752
Reputation: 47781
The pipeline
function from stream
or readable_stream
expects a callback as a last parameter.
var gulp = require('gulp');
var uglify = require('gulp-uglify');
var pipeline = require('readable-stream').pipeline;
gulp.task('compress', function (cb) {
return pipeline(
gulp.src('DIR_NAME/*.js'),
uglify(),
gulp.dest('DIR_NAME/dist'),
cb
);
});
stream/promises
exposes a promise-based version of pipeline
which does not use a callback:
var gulp = require('gulp');
var uglify = require('gulp-uglify');
var pipeline = require('stream/promises').pipeline;
gulp.task('compress', async function () {
await pipeline(
gulp.src('DIR_NAME/*.js'),
uglify(),
gulp.dest('DIR_NAME/dist')
);
});
Then there is the tradition way of piping steams, with the .pipe()
method.
var gulp = require('gulp');
var uglify = require('gulp-uglify');
gulp.task('compress', function () {
return gulp.src('DIR_NAME/*.js')
.pipe(uglify())
.pipe(gulp.dest('DIR_NAME/dist'));
});
Upvotes: 8