jsdf / browserify-incremental

incremental rebuild for browserify
175 stars 13 forks source link

Custom NODE_PATH breaks --require #9

Open joshfrench opened 9 years ago

joshfrench commented 9 years ago

I'm getting an ENOENT: can't open... error when I try to use --require in conjunction with a custom NODE_PATH (Rails app, can't get around the path issue.) The cachefile gets written initially, but the next time it's read it throws an error trying to read whatever file is passed to --require.

Here's a repo: https://github.com/joshfrench/browserifyinc-demo

To reproduce:

  1. git clone && npm install
  2. npm run build three times.

I suspect #8 is making it so you have to run the build an extra time up front, but once the cache actually gets read the error will occur.

joshfrench commented 9 years ago

I've been trying to chase this down with no luck. Any clues as to where I should start digging?

jsdf commented 9 years ago

Oh, is it a maximum open files issue? What OS are you on? Have you tried increasing the operating system's ulimit?

joshfrench commented 9 years ago

Seems unlikely, I'm able to reproduce on a minimal repo. My first thought was that the cache file just needed to use absolute paths, but if that's the case I haven't been able to find the right combination. (I'm also pretty inexperienced with Node, so it's entirely possible I've overlooked something obvious.)

lynndylanhurley commented 9 years ago

I'm having the same issue. @joshfrench - were you able to solve this?

joshfrench commented 9 years ago

I haven't been able to figure it out, unfortunately. We've just stopped using browserify-incremental, since the only workaround was to delete the cache file between changes and then recompile the bundle from scratch anyway :P

lynndylanhurley commented 9 years ago

@joshfrench - I was able to find a workaround.

Because --require is only broken for libraries in the node_modules folder, I was able to create a file within my own project that referenced all of the files that I want to be globals.

So it looks like this:

// globals.js
module.exports = {
  jquery: require('jquery'),
  lodash: require('lodash'),
  react: require('react')
};

And I can --require this file without any issues.

> browserifyinc -r my-project/globals ...

So if I need to reference these libraries globally, I can just do this:

window.$ = require('globals').jquery;
window._ = require('globals').lodash;
window.React = require('globals').react;
jsdf commented 9 years ago

@joshfrench Just realised this was related to https://github.com/jsdf/browserify-incremental/issues/7 as the specific version of browserify which is bundled with browserify-incremental has this issue, but a later version seems to have fixed it (I'm guessing it was ultimately caused by https://github.com/substack/module-deps/issues/30).

I've released a new version which removes the fixed browserify dependency version. Whatever version of browserify you install alongside browserify-incremental will be used. Using a recent version seems to fix your issue.

joshfrench commented 9 years ago

There's still something funky here, although at this point I don't know if it's browserify-incremental or module-deps or just the universe telling me to quit my job and open a nice cafe on the beach instead.

I can rebuild the cache without error now, but the resulting JS always throws RangeError: Maximum call stack size exceeded no matter what I'm trying to require. Here's a sample bundle with a single module (minus the require preamble.) The error is raised at apply(exports,arguments).

{"/Users/josh/src/browserifyinc-demo/in.js":[function(require,module,exports){
require('foo');
},{"foo":"foo"}],"foo":[function(require,module,exports){
module.exports = 'FOO';
},{}],"foo":[function(require,module,exports){
arguments[4]["foo"][0].apply(exports,arguments)
},{}]},{},["/Users/josh/src/browserifyinc-demo/in.js"]

I've updated my sample repo, to reproduce:

  1. git clone && npm install
  2. npm run clean
  3. npm run build && node out.js three times (still looks like the very first call doesn't actually write browserify-cache.json.)