I'm writing an app using atom/electron which is entirely built from an existing html/css/js source.
After a few hours tweaking grunt scripts i finally got something building. However, I kept getting the following error:
Uncaught ReferenceError: jQuery is not defined
After some playing around and general bashing my head against a wall I finally realised that this clever little bit of the jQuery source was to blame.
Inparticular, this line
if ( typeof module === "object" && typeof module.exports === "object" ) {
// Assume node context
}
So I'm not going insane. jQuery is in-fact loaded but it is bootstrapped to the node context instead of the browser context, causing all successive plugins to complain that window.jQuery is not defined.
My first thought was to throw in this cheeky snippet after the jquery source
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
global.jQuery = global.$ = window.jQuery = window.$ = module.exports;
}
This looks like it has done the trick. However, I'm no expert on atom/electron/webkit. Does anyone know of a cleaner way around this and whether changing the module.exports
of a file included in a <script>
tag is wise?
Cheers