1

I've seen a lot of disparate answers to similar issues, and I've tried a whole bunch of them. I've tried using gulp-streamify, and vinyl-buffer, I've tried using it without anything, but no matter what I do I get an error with Uglify whenever I include it in my gulp pipeline.

The following is the most relevant snippet of my code.

var bfyBundler = browserify({
    entries:['./src/sequencer.js'],
    extensions:['.jsx'],
    debug: devMode,
    cache: {}, packageCache: {}, fullPaths: true
});
function bundleSequencer(){
    var pipeline = bfyBundler.bundle()
        .on('error', function(error){
            notifier.notify({
                title:error.description,
                message:error.message,
                sound:true,
                wait:true,
                fileAndLocation:error.filename + ':' + error.lineNumber + ':' + error.column
            });
        });
    if(!devMode){
        pipeline = pipeline
            .pipe(uglify());
    }
    pipeline = pipeline
        .pipe(source('sequencer.js'))
        .pipe(gulp.dest('./app/'));
}

However running this pipeline returns the following error:

E:\Sequencer\node_modules\gulp-uglify\minifier.js:67  
    if (file.isNull()) {  
             ^

TypeError: file.isNull is not a function  
    at DestroyableTransform.minify [as _transform] (E:\Sequencer\node_modules\gulp-uglify\minifier.js:67:14)  
    at DestroyableTransform.Transform._read (E:\Sequencer\node_modules\through2\node_modules\readable-stream\lib\_stream_transform.js:172:10)  
    at DestroyableTransform.Transform._write (E:\Sequencer\node_modules\through2\node_modules\readable-stream\lib\_stream_transform.js:160:12)  
    at doWrite (E:\Sequencer\node_modules\through2\node_modules\readable-stream\lib\_stream_writable.js:326:12)  
    at writeOrBuffer (E:\Sequencer\node_modules\through2\node_modules\readable-stream\lib\_stream_writable.js:312:5)  
    at DestroyableTransform.Writable.write (E:\Sequencer\node_modules\through2\node_modules\readable-stream\lib\_stream_writable.js:239:11)  
    at Readable.ondata (E:\Sequencer\node_modules\readable-stream\lib\_stream_readable.js:572:20)  
    at emitOne (events.js:77:13)  
    at Readable.emit (events.js:169:7)  
    at readableAddChunk (E:\Sequencer\node_modules\readable-stream\lib\_stream_readable.js:195:16)

Using node-debug to trigger gulp it seems like gulp is passing in a Buffer object as opposed to a Vinyl file to Uglify. I welcome any input or methods that I can try to diagnose this issue.

I am using node v4.1.2 and gulp v3.9.0. So far as I can tell these are the latest versions. I'm wondering if something changed?

I've also posted this question to IRC, and hope for a quick resolution.

Codebling
  • 10,764
  • 2
  • 38
  • 66
Barak Gall
  • 1,422
  • 12
  • 24

2 Answers2

3

Ok, for anyone else having this same problem. the issue was I was using browserify and I had not piped through "source" before triggering uglify.. I also needed to pipe through buffer before uglify as source returns a streaming vinyl file object.

This SO is what helped me figure it out when I noticed the order of pipes: How to uglify output with Browserify in Gulp?

My solution for my code is:

var bfyBundler = browserify({
    entries:['./src/sequencer.js'],
    extensions:['.jsx'],
    debug: devMode,
    cache: {}, packageCache: {}, fullPaths: true
});
function bundleSequencer(){
    var pipeline = bfyBundler.bundle()
        .on('error', function(error){
            notifier.notify({
                title:error.description,
                message:error.message,
                sound:true,
                wait:true,
                fileAndLocation:error.filename + ':' + error.lineNumber + ':' + error.column
            });
        })
        .pipe(source('sequencer.js'));
    if(!devMode){
        pipeline = pipeline
            .pipe(buffer())
            .pipe(uglify());
    }
    pipeline = pipeline
        .pipe(gulp.dest('./app/'));
}
Barak Gall
  • 1,422
  • 12
  • 24
1

I see that you posted your own answer, but I'd like to add some additional info. Gulp plugins expect a steam of Vinyl file objects. Browserify.bundle() returns a stream (character stream) because it's not a Gulp plugin. Your original code would have worked if you used gulp-bro, which is a gulp plugin that calls Browserify.

See my answer on a related topic for more information.

Codebling
  • 10,764
  • 2
  • 38
  • 66