I have noticed that Browserify seems to have issues with multiple parent indicators, such as require('../../foo/bar').
An example of this is..
which results in..
Error: Cannot find module "/mnt/ws/users/$le/leeolayvar/555/examples/lib/foo" from directory "/mnt/ws/users/$le/leeolayvar/555"
Now, if we try and go one more directory up..
We end up with..
Error: Cannot find module "/mnt/ws/users/$le/leeolayvar/lib/foo" from directory "/mnt/ws/users/$le/leeolayvar/555"
You'll notice that in the 2nd example, Browserify skipped a directory. It went straight from leeolayvar/555/examples/lib/foo to leeolayvar/lib/foo.
So, i'm tracing the bug down and i noticed that in my execution of browserify on Line156 of Wrap.js, opts.root is undefined. Which means path.resolve is being fed from the root of the execution, instead of resolving relative to the source document.
A solution to this is rather simple, though i do not know the code base well enough at the moment to request a pull.
If you used something similar to this..
var x = r.match(/^(\.\.?)?\//) ? path.resolve(path.dirname(file), r) : r;
// var x = r.match(/^(\.\.?)?\//) ? path.resolve(opts.root, r) : r;
That would resolve the require path from the source document, rather than from the root directory, which is the way it should be.
Note that i am currently using the fix from above with no issues (yet)
Happy All Fools Day and:
npm install doubledot-browserify
But i would really like to know if node_modules is a right solution:
We should probably continue the discussion here, as i believe the two issues are slightly different.
Hopefully we can get @substack to comment on this issue. I was talking with him in IRC and i believe he said storing projects inside of node_modules was silly, but perhaps he was referencing something else :s
A work-around just landed in 1.10.17 that might fix this issue for some folks.
I'm hitting this same issue because I'm starting a daemon (using the middleware) from /
Error: Cannot find module "jquery-browserify" from directory "/"
at EventEmitter.require (/home/fieldid/Service/node_modules/browserify/lib/wrap.js:390:30)
at include (/home/fieldid/Service/node_modules/browserify/lib/wrap.js:331:14)
at Array.forEach (native)
at EventEmitter.requireMultiple (/home/fieldid/Service/node_modules/browserify/lib/wrap.js:309:16)
at EventEmitter.require (/home/fieldid/Service/node_modules/browserify/lib/wrap.js:343:21)
at HTTPServer.<anonymous> (/home/fieldid/Service/app.coffee:43:13)
server-side, the paths to installed node_modules are resolved properly. but browserify seems to expect the working dir to be the same as the source file. I'm using browserify 1.10.17, so that doesn't fix
Yep I've run into some of the same issues still. I started on a patch to overhaul how the targets are computed that waits until the bundle() step to compute the path destinations in the final bundle but it's a pretty massive change so it will take a while to get all the tests to pass.
Try now with email@example.com.