browserify / watchify

watch mode for browserify builds
Other
1.79k stars 181 forks source link

Error: write after end #322

Closed barbarosso closed 8 years ago

barbarosso commented 8 years ago

I have following peace of code, the first time the bundle gets called, the write succeeds, the second time i get following error.

events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: write after end
    at writeAfterEnd (_stream_writable.js:166:12)
    at WriteStream.Writable.write (_stream_writable.js:217:5)
    at Readable.ondata (/Users/pascalvanhecke/Projects/moovly/html5/editor-library/node_modules/readable-stream/lib/_stream_readable.js:531:20)

It has to do with the fact the stream is closed, but how should i give my outputfile?


var fs = require('fs');
var path = require('path');
var bundlePath = path.join(__dirname, 'bin', 'js', 'test.js');
var bundleFs = fs.createWriteStream(bundlePath);

var outputPath = path.join(__dirname, 'src', 'index.js');

var browserify = require('browserify');
var watchify = require('watchify');

var b = browserify({
    cache: {},
    packageCache: {},
    plugin: [watchify]
})
    .add(outputPath)
    .exclude('ga-browser"')
    .exclude('howler')
    .exclude('jquery')
    .exclude('object-assign')
    .exclude('react')
    .exclude('react-dnd')
    .exclude('react-dnd-html5-backend')
    .exclude('react-dom')
    .exclude('signals')
    .exclude('underscore')
    .exclude('webfontloader')
    .transform('reactify');

b.on('update', bundle);
bundle();

function bundle() {
    b.bundle().pipe(bundleFs);
}
barbarosso commented 8 years ago

The fix was to recreate the file, in the bundle function

function bundle() {
    b.bundle().pipe(fs.createWriteStream(bundlePath));
}