thlorenz / proxyquireify

browserify >= v2 version of proxyquire. Mocks out browserify's require to allow stubbing out dependencies while testing.
MIT License
152 stars 24 forks source link

Broken by new browserify versions? #1

Closed actionshrimp closed 10 years ago

actionshrimp commented 11 years ago

In order to use the proxyquireify.browserify() call in a project, I believe browserify needs to be listed as an normal (non-dev) dependency.

In my current setup I have proxyquireify and browserify in my package.json, and get this error when using the proxied browserify api:

TypeError: Cannot read property 'main' of undefined
    at /home/dave/dev/code/sevendigital-com/node_modules/proxyquireify/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/lib/async.js:91:54
    at load (/home/dave/dev/code/sevendigital-com/node_modules/proxyquireify/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/lib/async.js:54:43)
    at /home/dave/dev/code/sevendigital-com/node_modules/proxyquireify/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/lib/async.js:60:22
    at /home/dave/dev/code/sevendigital-com/node_modules/proxyquireify/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/lib/async.js:16:47
    at Object.oncomplete (fs.js:107:15)

However if I cd into node_modules/proxyquireify and do npm install to fetch ALL dependencies, the error goes away.

I've tried just installing browserify in node_modules/proxyquireify which I thought might fix it, but it doesn't seem to have.

I did some digging on the error line and there are two variables, in scope at that time 'x' and 'pkg'. 'x' has the value '/full/path/to/node_modules/proxyquireify', and pkg is undefined (which is what throws the error).

Cheers Dave

actionshrimp commented 11 years ago

Nope, I lie actually, moving browserify from devDependencies into dependencies and then running npm install --production does fix the problem.

Not sure if this is just a typo mistake or you've deliberately left browserify out but it does seem to make sense for it to be a dependency to me. I'll make a pull request now.

actionshrimp commented 11 years ago

Nope - I played around with the example project a bit and saw how that is meant to work, and noticed it was on an older version of browserify. Downgrading in my package.json has got my build further (although I'm getting a separate error now which I'm pretty certain is unrelated). So it looks like some changes in browserify must have broken something - 2.25.0 gave me the error, but 2.10.0 does not.

Thanks Dave

actionshrimp commented 11 years ago

After some more digging this looks to be caused by browserify upgrading the module-deps verison number between versions 2.19.0 and 2.20.0. Not sure why this has the effect it does though.

thlorenz commented 10 years ago

Yeah could be, right now the prelude is adapted from some much older browserify version. I'll look at it when I get a chance unless you get ahead of me with a PR.

Thanks for digging into this.

thlorenz commented 10 years ago

Could you please try to see if that is fixed in the latest version (some major changes, so hopefully they addressed your changes).