Closed cyruszah closed 9 years ago
Exactly. Whoever publishes a module that needs shimming needs to include the browserify-shim config.
This is something we won't change. Contact the author of the module you're using to add the shim config instead.
when an installed node_module like backbone does a 'require('jquery)
If that module requires jquery
without depending on it in the package.json, then that's a bug.
I'm sure this has been fixed by now, so upgrade your backbone version, otherwise bug the backbone authors to fix it ;)
@thlorenz, it's not that backbone
actually needs shimming: If my application's package.json
simply specifies a dependency on jquery
, then backbone
's require('jquery')
will just find it. In that sense, jquery
is more like a peer dependency of backbone
.
If, on the other hand I choose to load jquery
externally through a CDN, I can expose that to the rest of my application through @cyruszah's browserify-shim
declaration.
I, too, was fully expecing that shim to be a drop-in replacement for `require('jquery') at any level; my application's code, as well as its dependencies.
In other words, I was not expecting the latter case to be any different from the former.
Same issue here with Magnific Popup, which also uses the same idiom to load jQuery (and I'm not the only one). The hard cutoff at node_modules
is surprising and frustrating, and I can't find any clean workaround with browserify-shim. (I can go straight to browserify and write my own shim.)
The hard cutoff at node_modules is surprising and frustrating
It's how browserify works. Transforms don't run on node_modules unless you make them global transforms.
I have the following setup in my package.json file:
"browserify": { "transform": [ "browserify-shim" ] }, "browserify-shim": { "jquery": "global:$" }
This works fine except when an installed node_module like backbone does a 'require('jquery)', browserify-shim transform will not apply to the node_module and give me an error saying it can not find the jquery module.
If I add the above code to the package.json file of node_modules/backbone all woks fine.