eugeneware / debowerify

A browserify transform to enable the easy use of bower components in browserify client javascript projects. This can be used in conjunction with deamdify to require AMD components from bower as well.
493 stars 51 forks source link

Does not work with react-bootstrap #59

Open EvanCarroll opened 9 years ago

EvanCarroll commented 9 years ago

Simple test with react-bootstrap

https://github.com/EvanCarroll/debowerify-fail

$ sh FAIL.sh 
Error: Cannot find module './joinClasses' from '/tmp/fail/public/bower_components/react-bootstrap'
    at /usr/local/lib/node_modules/browserify/node_modules/resolve/lib/async.js:42:25
    at load (/usr/local/lib/node_modules/browserify/node_modules/resolve/lib/async.js:60:43)
    at /usr/local/lib/node_modules/browserify/node_modules/resolve/lib/async.js:66:22
    at /usr/local/lib/node_modules/browserify/node_modules/resolve/lib/async.js:21:47
    at Object.oncomplete (fs.js:93:15)

react-bootstrap/index.js has a series of requires

Accordion: require('./Accordion')

While the file, ./Acordion.js has itself a series of requires.

var joinClasses = require('./utils/joinClasses');

These don't seem to be resolvable with react-bootstrap.

bobthecow commented 9 years ago

That's because the bower version of react-bootstrap isn't CommonJS compatible, it's made for using in a browser.

Per their bower.json, the main file is react-bootstrap.js, a pre-built AMD/browser global file that's not meant to be used inside node or browserify or anything else that uses CommonJS.

Note that even if you included react-bootstrap/index.js directly, you'll still be headed down a path of sadness, since that is an AMD file, not a CommonJS file.

So either convince react-bootstrap to use UMD instead of AMD in their pre-built file, or use a non-bower version of react-bootstrap (possibly the npm version?), or try to figure out the exact right deamdify+debowerify+shim combination to trick the bower version into playing nice :)

EvanCarroll commented 9 years ago

Can we at least fail intelligibly? Is it possible in this situation?

bobthecow commented 9 years ago

It has nothing to do with debowerify, and everything to do with the fact that calling require() on a non-CommonJS file just doesn't work. And it's not debowerify's place to catch that, even if it is possible. This issue is why deamdify exists, and you might have some luck using that :)