sandrooco
sandrooco

Reputation: 8736

Gulp/Lazypipe: Error: Invalid call to lazypipe().pipe(): argument is not a function

I receive the error as stated:

Error: Invalid call to lazypipe().pipe(): argument is not a function.

Remember not to call stream creation functions directly! e.g.: pipe(foo), not pipe(foo()).

That makes totally sense to me (especially because there are already some related questions), but how can I pass params to the lazypipe?

function buildPipes(fileName) {
    return lazypipe()
        .pipe($.concat(fileName))
        .pipe(gulp.dest(destFull))
        .pipe($.rename(minFileName))
        .pipe($.babel({
            presets: ["es2015"]
         }))
        .pipe($.uglify({
            compress: {
                hoist_funs: false
            }
         }))
        .pipe(gulp.dest(dest));
}

Another part of my script, consuming the pipe:

var vendor = gulp.src(sources.vendor).pipe(buildPipes(fileName));

Upvotes: 2

Views: 996

Answers (1)

Sven Schoenung
Sven Schoenung

Reputation: 30574

The lazypipe docs give several examples how to pass parameters to plugins. Here's one:

var jsTasks = jsHintTasks
    .pipe(gulp.dest, 'build/js');

More generalized: for any plugin function foo which returns a stream.Transform the following conversions apply:

normal usage -> lazypipe usage

  • .pipe(foo()) -> .pipe(foo)
  • .pipe(foo(param1)) -> .pipe(foo, param1)
  • .pipe(foo(param1, param2)) -> .pipe(foo, param1, param2)
  • etc..

In your case:

function buildPipes(fileName) {
  return lazypipe()
    .pipe($.concat, fileName)
    .pipe(gulp.dest, destFull)
    .pipe($.rename, minFileName)
    .pipe($.babel, {
        presets: ["es2015"]
     })
    .pipe($.uglify, {
        compress: {
            hoist_funs: false
        }
     })
    .pipe(gulp.dest, dest);
}

Also note that lazypipe().pipe(foo) doesn't return a stream. It returns a function that returns a stream, so you need to invoke that function if you want to pipe the constructed lazypipe to another stream. That means instead of:

var vendor = gulp.src(sources.vendor).pipe(buildPipes(fileName));

You need to do this:

var vendor = gulp.src(sources.vendor).pipe(buildPipes(fileName)());

(Alternatively you could do the function invocation in the buildPipe() function itself as seen in this example)

Upvotes: 3

Related Questions