jQuery isn't set globally because "module" is defined #254
Comments
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: window.$ = window.jQuery = require('/path/to/jquery'); |
I agree with @ChiperSoft, this is expected behavior in CommonJS environment, so I marked this as |
@ChiperSoft, Where should I put the jquery.js file to get |
You can use |
Atom shell appears to blow up when jquery is added as script tag. electron/electron#254 Use commonjs syntax to export to window
Sorry, I used |
I use that all the time and it works great! Here is what I use, be mindful about the path: window.$ = window.jQuery = require('./scripts/jquery-2.1.1.min.js'); |
@frankhale oh, it worked with |
Awesome! The path thing tripped me up as well. |
Stop depending on jQuery and Vex, because electron/electron#254 is just ridiculous when loading non-file resources (__dirname is not set properly and process.cwd() is not usable)
If your app does not need node-integration, add |
@kabalage worked wonderfully, thanks! |
|
Walked up to the same issue. Install jQuery via NPM then required it and it worked. |
what if node integeration and jquery without the require is needed... |
I'm trying to make sense of this since it appears to be something I could use. However I wonder when can you be sure you can safely use $. Logging $ right after this line will result would be require and not jquery since require is asynchronus? window.$ = window.jQuery = require('/path/to/jquery'); |
@dieroux try installing it via npm:
This worked for me while trying the same. Then you don't need to give a path, you just say: window.$ = window.jQuery = require('jquery');
console.log( [$, jQuery ]); |
Fixed an error with jQuery not running properly with Twitter bootstrap and the Electron framework. Reference: electron/electron#254
What if we need node-integration, and we can't use require('something') ? |
For some reason I'm still not able to make jQuery work both in browser and in Electron app. Webapp - https://github.com/zulip/zulip The webapp is using jquery 1.12.1 version via npm. |
@englishextra no luck. I tried to include your code into my app's preload.js but getting same error. |
@englishextra No, I don't need jquery in my app. See the update code here. I can't include your code into my app logic since I'm using it only for loading the specified url see this. |
for those using the Aurelia framework: |
I resolved this problem with this
and set
if you with
reference to |
I mean, it seems to be a bad problem, so why not include it in actual Electron? Maybe integrate major JavaScript libraries into Electron? |
Chances are, if you are using jQuery in an Electron App, you are doing something very wrong or at least inefficient. |
|
@drowlands Including 3party libs in Electron seems to be a bad idea. Imagine the update routine, for instance, or chosing a version. Here:
I my case I load libs via fetch/Promise or xhr, so I have this routine to remove module checks in vendors' libs. |
mark |
@kabalage I think the configuration in your post above is out of date. It looks like it should be like this now: const window = new BrowserWindow({
webPreferences: {
nodeIntegration: false,
},
}); |
…nt_patch set dock state using devtools dockController
…nt_patch set dock state using devtools dockController
On official docs:
|
I'm getting preload script is
|
if i use this code, it works fine, |
jQuery contains something along this lines:
module is defined, even in the browser-side scripts. This causes jQuery to ignore the
window
object and usemodule
, so the other scripts won't find$
norjQuery
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.
The text was updated successfully, but these errors were encountered: