Closed
Description
jQuery contains something along this lines:
if ( typeof module === "object" && typeof module.exports === "object" ) {
// set jQuery in `module`
} else {
// set jQuery in `window`
}
module is defined, even in the browser-side scripts. This causes jQuery to ignore the window
object and use module
, so the other scripts won't find $
nor jQuery
in global scope..
I am not sure if this is a jQuery or atom-shell bug, but I wanted to put this on the web, so others won't search as long as I did.
Activity
Twipped commentedon May 6, 2014
This isn't really a bug for either system, you have the same problem when using browserify. jQuery sees that its running in a CommonJS environment and expects to be used as such.
The solution is relatively simple, however. Instead of loading jQuery as a script tag, load it via require:
zcbenz commentedon May 7, 2014
I agree with @ChiperSoft, this is expected behavior in CommonJS environment, so I marked this as
wontfix
. And thanks for sharing your finding.alexdong commentedon Jun 7, 2014
@ChiperSoft, Where should I put the jquery.js file to get
require('jquery')
working? I've tried to put it at the same level aspackage.js
andmain.js
but the runtime doesn't seem to pick it up.JoshTheDerf commentedon Jun 7, 2014
You can use
require('jquery.js')
note the .js at the end, to load jquery relative to your HTML file.require jQuery fix for atom-shell
mpcode commentedon Sep 28, 2014
Sorry, I used
window.$ = window.jQuery = require('/path/to/jquery');
as mentioned but it doesn't work,Uncaught Error: Cannot find module 'scripts/jquery-1.10.2.min.js' module.js:339
frankhale commentedon Sep 28, 2014
I use that all the time and it works great! Here is what I use, be mindful about the path:
mpcode commentedon Sep 28, 2014
@frankhale oh, it worked with
./
, thanks!frankhale commentedon Sep 28, 2014
Awesome! The path thing tripped me up as well.
130 remaining items