mgcrea / gulp-through

Gulp stream transform factory
MIT License
8 stars 2 forks source link

has no method 'on' #1

Open pearmaster opened 8 years ago

pearmaster commented 8 years ago

I'm trying to use gulp-through, but when I run my gulp task, it complains that the transform method "has no method 'on'".

Here is my gulp task:

gulp.task('base64encode', function () {
    var through = require('gulp-through');
    var base64encode = through('base64encode', function (file, config) {
        // actually do nothing for now
    });
    return gulp.src('myfile.bin')
        .pipe(base64encode)
        .pipe(gulp.dest("/tmp"));
});

And here is the error message I get when I run it in gulp version 3.8.11:

[14:53:26] Using gulpfile /work/myproject/Gulpfile.js
[14:53:26] Starting 'base64encode'...
[14:53:28] 'base64encode' errored after 1.93 s
[14:53:28] TypeError: Object function (options) {

    var config = extend(defaults, options);

    function transform(file, encoding, next) {

      var emit = this.emit;

      if(file.isNull()) {
        return next(null, file); // pass along
      }

      Promise.resolve(callback.call(this, file, config))
      .then(function() {
        if(config.debug) {
          gutil.log(util.format('Processed \'%s\' through %s', chalk.cyan(path.relative(process.cwd(), file.path)), chalk.magenta(name)));
        }
        next(null, file);
      })
      .catch(function(err) {
        if(config.safe) {
          return gutil.log(util.format('Encountered the following error while processing \'%s\' through %s\n%s', chalk.cyan(path.relative(process.cwd(), file.path)), chalk.magenta('jade'), chalk.red(err)));
        }
        emit('error', new gutil.PluginError(name, err));
      });

    }

    return through.obj(transform);

  } has no method 'on'
    at DestroyableTransform.Readable.pipe (/work/myproject/node_modules/gulp/node_modules/vinyl-fs/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:516:8)
    at Gulp.<anonymous> (/work/myproject/Gulpfile.js:179:10)
    at module.exports (/work/myproject/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:34:7)
    at Gulp.Orchestrator._runTask (/work/myproject/node_modules/gulp/node_modules/orchestrator/index.js:273:3)
    at Gulp.Orchestrator._runStep (/work/myproject/node_modules/gulp/node_modules/orchestrator/index.js:214:10)
    at Gulp.Orchestrator.start (/work/myproject/node_modules/gulp/node_modules/orchestrator/index.js:134:8)
    at /usr/local/lib/node_modules/gulp/bin/gulp.js:129:20
    at process._tickCallback (node.js:415:13)
    at Function.Module.runMain (module.js:499:11)
    at startup (node.js:119:16)
    at node.js:902:3
wulechuan commented 6 years ago

source code snippet:

return gulp.src(sourceIndexingFile)
    // .pipe(replaceContent(/^([\s\S])*?(\n\s*export\b)/, 'export'))
    .pipe(through('we are removing heading part', (file, config) => {
      console.log('v'.repeat(30));
      console.log(file);
      console.log('^'.repeat(30));
    }))
    .pipe(/* ... */);

console log:

D:\[omitted path here]\node_modules\thunks\index.js:385
      else throw error
           ^

TypeError: dest.on is not a function
    at DestroyableTransform.Readable.pipe (D:\[omitted path here]\node_modules\vinyl-fs\node_modules\readable-stream\lib\_stream_readable.js:516:8)
    at evaluateIndexingLESSFileContentViaTSXFile (D:\[omitted path here]\toolchain\lib\gulp-tasks\css-compile-less-in-multi-themes.js:40:10)
    at Gulp.gulp.task (D:\[omitted path here]\gulp-tasks\css-compile-less-in-multi-themes.js:87:34)
    at module.exports (D:\[omitted path here]\node_modules\orchestrator\lib\runTask.js:34:7)
    at Gulp.Orchestrator._runTask (D:\[omitted path here]\node_modules\orchestrator\index.js:273:3)
    at Gulp.Orchestrator._runStep (D:\[omitted path here]\node_modules\orchestrator\index.js:214:10)
    at Gulp.Orchestrator.start (D:\[omitted path here]\node_modules\orchestrator\index.js:134:8)
    at D:\[omitted path here]\node_modules\gulp-sequence\index.js:68:12
    at apply (D:\[omitted path here]\node_modules\thunks\index.js:355:38)
    at tryRun (D:\[omitted path here]\node_modules\thunks\index.js:225:19)
    at runThunk (D:\[omitted path here]\node_modules\thunks\index.js:218:15)
    at D:\[omitted path here]\node_modules\thunks\index.js:315:49
    at apply (D:\[omitted path here]\node_modules\thunks\index.js:355:38)
    at tryRun (D:\[omitted path here]\node_modules\thunks\index.js:225:19)
    at runThunk (D:\[omitted path here]\node_modules\thunks\index.js:218:15)
    at continuation (D:\[omitted path here]\node_modules\thunks\index.js:165:10)
npm ERR! code ELIFECYCLE
npm ERR! errno 1