debowerify icon indicating copy to clipboard operation
debowerify copied to clipboard

Does not work with react-bootstrap

Open EvanCarroll opened this issue 10 years ago • 3 comments

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.

EvanCarroll avatar Feb 11 '15 02:02 EvanCarroll

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 :)

bobthecow avatar Feb 11 '15 05:02 bobthecow

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

EvanCarroll avatar Feb 11 '15 06:02 EvanCarroll

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 :)

bobthecow avatar Feb 11 '15 06:02 bobthecow