browserify / factor-bundle

factor browser-pack bundles into common shared bundles
Other
402 stars 27 forks source link

factor-bundle doesn't work with watchify #63

Closed rubennorte closed 9 years ago

rubennorte commented 9 years ago

I'm getting this error when using them together, both in Windows 7 and in Linux (Node v0.10) with their latest versiong (watchify 2.4.0 and factor-bundle 2.4.0):

watchify resources/js/src/pages/a.js resources/js/src/pages/b.js -p [ factor-bundle -o web/js/page-a.js -o web/js/page-b.js ] -o web/js/shared.js

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: write after end
    at writeAfterEnd (_stream_writable.js:133:12)
    at WriteStream.Writable.write (_stream_writable.js:181:5)
    at Labeled.ondata (C:\code\project\node_modules\factor-bundle\node_modules\labeled-stream-splicer\node_modules\stream-splicer\node_modules\readable-stream\lib\_stream_readable.js:572:20)
    at Labeled.emit (events.js:95:17)
    at readableAddChunk (C:\code\project\node_modules\factor-bundle\node_modules\labeled-stream-splicer\node_modules\stream-splicer\node_modules\readable-stream\lib\_stream_readable.js:195:16)
    at Labeled.Readable.push (C:\code\project\node_modules\factor-bundle\node_modules\labeled-stream-splicer\node_modules\stream-splicer\node_modules\readable-stream\lib\_stream_readable.js:162:10)
    at Labeled.Pipeline._read (C:\code\project\node_modules\factor-bundle\node_modules\labeled-stream-splicer\node_modules\stream-splicer\index.js:56:31)
    at Labeled.onreadable (C:\code\project\node_modules\factor-bundle\node_modules\labeled-stream-splicer\node_modules\stream-splicer\index.js:63:18)
    at Labeled.g (events.js:180:16)
    at Labeled.emit (events.js:92:17)

The error started happening when the bundle files started to grow (~100KB, not that much), so maybe you didn't discovered the error testing it in small bundles.

Any clue? Thanks!

davidsmith2 commented 9 years ago

Having the same issue. Any help much appreciated.

idolizesc commented 9 years ago

Likewise hitting the same issue

idolizesc commented 9 years ago

As a temporary workaround: I've discovered reverting to an old version fixes the issue.

package.json:

"factor-bundle": "~2.3.2"
abritinthebay commented 9 years ago

another workaround - just install the watch package globally and be able to watch anything and trigger anything from it (ie - watch "browserify -p [factor-bundle]" location/of/files

ponelat commented 9 years ago

+1 Same error here. I'm using gulp + browserify + watchify + factor-bundle@2.4.0 I reverted, to 2.3.2 but it didn't like my setup - however it works with factor-bundle@2.3.3. @idolizesc thanks for the idea of reverting.

bstst commented 9 years ago

Same here. 2.3.3 works great with watchify.

2.4.0 works when the build is started anew, but after the bundles are rebuilt by watchify -- the same error appears.

geirsagberg commented 9 years ago

Same problem here. Reverting to 2.3.3 works for me.

matekb commented 9 years ago

Same for me. Reverting to 2.3.3 works for me too.

Checksum commented 9 years ago

2.3.3 worked for me as well. Thanks!

foray1010 commented 9 years ago

confirmed 2.4.1 still not working

aben commented 9 years ago

Because watchify or factor-bundle that write to multiple files or write to the same file more than once, If output is a function that return a writable stream, will be done. my fork

function write (name) {
    return concat(function (body) {
        console.log('// ----- ' + name + ' -----');
        console.log(body.toString());
    });
}
function outputs(filename) {
    return write(filename)
} 
b.plugin(factor, { outputs: outputs});
b.bundle().pipe(write('common.js'))
aquach commented 9 years ago

@Aben exactly what I needed! Thanks!

thallada commented 9 years ago

I don't understand the example @Aben gave. What is filename here?

The use-case @rubennorte gave has factor-bundle outputting two files (page-a.js and page-b.js) in addition to shared.js. If the outputs is set to a function that is called once and can only return one filename or writable stream, how can factor-bundle output to more than one file using this method?

aquach commented 9 years ago

In @Aben's example, outputs is a function that watchify will invoke once for each file in the entries parameter passed to watchify. The function's job is to translate an output filename into a stream writing to that filename.

Each entry in entries is transformed into an output stream via the function passed to outputs, so you end up with one stream for each file (such as page-a or page-b).