The setup below has been adapted from this browserify-shim example.
The code can simply require(jquery)
because browserify-shim
will replace these with window.jQuery
, expecting that it will have been exposed there, loaded from a CDN via a <script>
tag. So far, this part works.
The key difference with the original example is that this code also wants to require('backbone')
(a regular npm install).
Backbone also does a require('jquery')
and I was expecting this to just work too.
Except, that it doesn't, as this statement will demonstrate:
npm install
result:
> [email protected] install /tmp/expose-jquery
> browserify -d . > bundle.js
Error: Cannot find module 'jquery' from '/tmp/expose-jquery/node_modules/backbone'
at /tmp/expose-jquery/node_modules/browserify/node_modules/resolve/lib/async.js:46:17
at process (/tmp/expose-jquery/node_modules/browserify/node_modules/resolve/lib/async.js:173:43)
at ondir (/tmp/expose-jquery/node_modules/browserify/node_modules/resolve/lib/async.js:188:17)
at load (/tmp/expose-jquery/node_modules/browserify/node_modules/resolve/lib/async.js:69:43)
at onex (/tmp/expose-jquery/node_modules/browserify/node_modules/resolve/lib/async.js:92:31)
at /tmp/expose-jquery/node_modules/browserify/node_modules/resolve/lib/async.js:22:47
at FSReqWrap.oncomplete (fs.js:95:15)
I expect a perspective exist from which this makes sense, however I fail to see it.
same problem here..