Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Error: write after end" with browserify 7.x #24

Closed
jmm opened this issue Dec 23, 2014 · 23 comments · Fixed by #35
Closed

"Error: write after end" with browserify 7.x #24

jmm opened this issue Dec 23, 2014 · 23 comments · Fixed by #35
Assignees

Comments

@jmm
Copy link

jmm commented Dec 23, 2014

Given the following directory structure and build script (on linux):

- project
  - src
    - rsrc
      entry.js
      - view
        game.js
// entry.js
require("app/view/game");
var
  browserify = require('browserify'),
  remapify = require('remapify'),
  fs = require('fs'),
  remapify_opts,
  b;

remapify_opts = [
  {
    src: './**/*.js',
    expose: 'app',
    cwd: './src/rsrc',
  }
];

b = browserify('./src/rsrc/entry')
      .plugin(remapify, remapify_opts)
      .bundle()
      .pipe(process.stdout);

It works with browserify 6.3.4, but generates the following error with >= 7.0.0:

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: write after end
    at writeAfterEnd (/project/node_modules/browserify/node_modules/labeled-stream-splicer/node_modules/stream-splicer/node_modules/readable-stream/lib/_stream_writable.js:161:12)
    at Labeled.Writable.write (/project/node_modules/browserify/node_modules/labeled-stream-splicer/node_modules/stream-splicer/node_modules/readable-stream/lib/_stream_writable.js:208:5)
    at Browserify.transform (/project/node_modules/browserify/index.js:275:23)
    at done (/project/node_modules/remapify/lib/remapify.js:38:9)
    at Glob.globEnd (/project/node_modules/remapify/lib/remapify.js:94:9)
    at Glob.emit (events.js:95:17)
    at Glob.next (/project/node_modules/remapify/node_modules/glob/glob.js:343:12)
    at Glob._processEmitQueue (/project/node_modules/remapify/node_modules/glob/glob.js:310:12)
    at Glob.emitMatch (/project/node_modules/remapify/node_modules/glob/glob.js:290:8)
    at Glob._finish (/project/node_modules/remapify/node_modules/glob/glob.js:230:8)
@tnguyen14
Copy link

I am running into the same issue.

@sam3k
Copy link

sam3k commented Dec 29, 2014

Any update on this? I'm also encountering this error. Can I downgrade to a particular commit to get this going? Thanks.

@joeybaker
Copy link
Owner

Hi guys - I'm not around a computer for the next week, but will look into it after that. In the meantime, a PR would be very much appreciated too!

@joeybaker
Copy link
Owner

Your best bet would be to downgrade browserify if you need this now — I know that's a sucky answer though — sorry!

@joeybaker
Copy link
Owner

@jmm @tnguyen14 @sam3k I might be brain-dead (it was a long day), but I'm really struggling to come up with a failing test case here. I just published 1.4.4 which adds sets a new~ish aliasify option. Maybe, maybe, maybe that solves something?

I'd really, really, appreciate a PR that has a failing test case.

@jmm
Copy link
Author

jmm commented Jan 7, 2015

The nature of the problem is a race condition, so its appearance is going to be hit or miss. I just tried again with 1.4.4 and it still happens. If you've been unable to reproduce it, I suggest you try something like this:

var sleep = function (duration) {
  var now = (new Date).getTime();
  while ((new Date).getTime() < now + duration) {}
};

var filter = function (alias, dir, base) {
  sleep(10000);
  return path.join(dir, base);
};

var remapify_opts = [
  {
    // Glob that only matches one file
    src: './view/**/*.js',
    expose: 'app',
    cwd: './src/rsrc',
    filter: filter,
  }
];

@joeybaker
Copy link
Owner

That's a great help! Thanks!

@roncli
Copy link

roncli commented Jan 8, 2015

d78e8cb (which references this issue) broke some existing functionality. I can no longer do this:

                        b.plugin(remapify,
                            {
                                cwd: "./app",
                                src: "**/*.js",
                                expose: "app"
                            }
                        );

This gives the error:

>> Error: module "./../../../app/app/router.js" not found from "...\\node_modules\\rendr\\shared\\app.js"
Warning: Error running grunt-browserify. Use --force to continue.

I must instead do this:

                        b.plugin(remapify,
                            {
                                cwd: "./",
                                src: "app/**/*.js",
                                expose: ""
                            }
                        );

However, there is no workaround for something like this:

                        b.plugin(remapify,
                            {
                                cwd: "./admin",
                                src: "**/*.js",
                                expose: "app"
                            }
                        );

@joeybaker Let me know if you want me to open a separate ticket for this issue.

@joeybaker
Copy link
Owner

All of this is related to the pipeline changes introduced by browserify v7. I'm working on a fix, but if someone gets there before me, I won't mind! :)

@jmm
Copy link
Author

jmm commented Jan 13, 2015

I don't understand the rationale for bumping (4c0faee) the browserify versions in the dependencies to versions that this currently doesn't work with?

@roncli
Copy link

roncli commented Jan 13, 2015

@joeybaker I am not able to check on this because grunt-browserify@3.2.1, which is the latest, is using browserify@6.3.4.

With that said, my latest successful attempt involves the following:

        browserify: {
            combine_main_js_files: {
                options: {
                    require: Object.keys(pjson.browser),
                    preBundleCB: function(b) {
                        b.on("remapify:files", function(file, expandedAliases) {
                            Object.keys(expandedAliases).forEach(function(key) {
                                if (key.indexOf(".js") === -1 && key.indexOf("\\") === -1) {
                                    b.require(path.resolve(expandedAliases[key]), {expose: key});
                                }
                            });
                        });
                        b.plugin(remapify,
                            {
                                cwd: "./app",
                                src: "**/*.js",
                                expose: "app"
                            }
                        );
                    }
                },
                files: {
                    "assets/js/site.js": ["app/**/*.js"]
                }
            }
        },

I have not tried 1.4.4 with this setup yet, but will do so tomorrow and report the results.

@roncli
Copy link

roncli commented Jan 14, 2015

Confirmed, I got this working with 1.4.4. More details in #26.

@tleunen
Copy link

tleunen commented Jan 16, 2015

Any update on this fix?

@joeybaker joeybaker self-assigned this Jan 19, 2015
joeybaker added a commit that referenced this issue Jan 21, 2015
@joeybaker
Copy link
Owner

I've made progress here: https://github.com/joeybaker/remapify/tree/fix24 I'm hoping to finish this real soon. Sorry for the inconvenience!

@heroicyang
Copy link

Hope to fix the problem, thanks! 😊

@sam3k
Copy link

sam3k commented Jan 25, 2015

Really looking forward the fix. Thanks.

joeybaker added a commit that referenced this issue Jan 30, 2015
@lorenmh
Copy link

lorenmh commented Feb 14, 2015

Spent an hour trying to figure out what was wrong, please fix!

Switching to 6.3.4 (from jmm) got it working for me.

@dreadwail
Copy link

This has been broken since mid-December with the last update from @joeybaker being 1.5 months ago. Is there any path forward here? Any alternatives? I attempted to lock down versions to older versions but had no success.

@roncli
Copy link

roncli commented Feb 27, 2015

@benlakey I am using my patch from https://github.com/roncli/remapify/compare/roncli:master...issue-24-from-1.4.4 to temporarily workaround this issue.

Alternatively, you can downgrade to 1.4.3 and grunt-browserify 2.1.4, those two play well together.

@joeybaker
Copy link
Owner

Yes, there is a path forward. I've been super tied up at work and haven't had much time to finish the fix. It deals with using browserify's new pipeline API. I'm working on it in the fix24 branch, feel free to add on if you have time!

@dreadwail
Copy link

@joeybaker Cool I figured it was something like that. Just wasn't sure if this project was abandoned in favor of some alternative. @roncli I'll try the downgrade versions you mention.

@JesseFarebro
Copy link

Tried out the fix24 branch, it fixes the write after end bug, but some other issues are present. Would like to see this issue get some more light

@TheBizzle
Copy link

🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet