最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - gulp generates TypeError: The Streams property must be of type function - Stack Overflow

matteradmin7PV0评论

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 'press'...
'press' 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('press', 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"
    }
}

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 'press'...
'press' 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('press', 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"
    }
}
Share Improve this question asked Jan 14, 2023 at 13:25 Hady ShaltoutHady Shaltout 6301 gold badge9 silver badges23 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

Solution 1

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('press', function (cb) {
    return pipeline(
        gulp.src('DIR_NAME/*.js'),
        uglify(),
        gulp.dest('DIR_NAME/dist'),
        cb
    );
});

Solution 2

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('press', async function () {
    await pipeline(
        gulp.src('DIR_NAME/*.js'),
        uglify(),
        gulp.dest('DIR_NAME/dist')
    );
});

Solution 3

Then there is the tradition way of piping steams, with the .pipe() method.

var gulp = require('gulp');
var uglify = require('gulp-uglify');

gulp.task('press', function () {
    return gulp.src('DIR_NAME/*.js')
        .pipe(uglify())
        .pipe(gulp.dest('DIR_NAME/dist'));
});
Post a comment

comment list (0)

  1. No comments so far