browserify / factor-bundle

factor browser-pack bundles into common shared bundles
Other
400 stars 27 forks source link

react-bootstrap, lodash, and factor-bundle not playing well together #79

Closed micah-bloomerang closed 8 years ago

micah-bloomerang commented 8 years ago

I've been working on this problem for a couple of days, and I think I finally have it narrowed down. If I'm using factor-bundle where one file contains a reference to lodash and the other file contains a reference to react-bootstrap, I get the following error:

TypeError: Cannot read property '0' of undefined

Here is what is needed to reproduce:

npm install factor-bundle lodash react-bootstrap

index.html

<html>
<body>
<script type="text/javascript" src="bundle/common.js"></script>
<script type="text/javascript" src="bundle/index.js"></script>
</body>
</html>

main/index.js

require('../node_modules/react-bootstrap');

main/bad.js

require('../node_modules/lodash/object/keys');

Build with:

browserify main/index.js main/bad.js -p [ factor-bundle -o bundle/index.js -o bundle/bad.js ] -o bundle/common.js
djforth commented 8 years ago

+1 I'm getting a similar issue

micah-bloomerang commented 8 years ago

@djforth any differences in your issue? Maybe we can find a common thread.

mrkrstphr commented 8 years ago

This seems related to https://github.com/substack/factor-bundle/issues/51

djforth commented 8 years ago

Hi Sorry for the late reply, I think my issue was 2 fold. Firstly my common bundle seemed to loading after my other bundles because of async and secondly it was a dependancy mismatch. Once I had sorted it so that my internal modules where all the same + using peerDependancy over dependancy in the modules the issue seemed to disappear. Hope that helps.

magalhini commented 8 years ago

I'm having the exact same issue and I am quite, quite desperate now. It took me three days to narrow it down to factor-bundle... apparently, if I require more than one module twice with Browserify, I'm also getting the following error:

TypeError: Cannot read property '0' of undefined

If I duplicate a module and give it a different name, everything works as expected. This was working fine until I recently updated React and Babel to their latest versions (React 0.13 and Babel 5.x were working fine). Any leads?

magalhini commented 8 years ago

@djforth Could you please give me some more details about your dependency mismatch? How did you narrow them down to the root cause?

tellnes commented 8 years ago

This might be related to the problem in browser-pack that browserify entries are required before the require method is exposed to the global scope. When you are using multiple bundles browserify depends on a global require variable.

I've got an open pull request fixing that (https://github.com/substack/browser-pack/pull/73), but it has no response yet.

micah-bloomerang commented 8 years ago

I was only seeing this issue in lodash v3 (was using v3.10.1), but after upgrading lodash to v4 (v4.6.1), I no longer see the issue. Closing.