You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
jQuery isn't set globally because "module" is defined #254
if(typeofmodule==="object"&&typeofmodule.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.
Reacted by Karuppiah Natarajan, Davide Onofrio, Leonid Suprun, Alex Chesters, Oded Breiner, Akash, Marco Chávez, Justin, Benoit Debled, Jan Olszak and 12 more
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:
Reacted by Krestian Weken, Tim, Kirk Brauer, Trevor Clarke, Charley DAVID, Afshin Mehrabani, sagepa, tao, Tihomir Valkanov, Karuppiah Natarajan and 50 more
Reacted by URYU, Natesh Bhat, Alistair Smith and Juan Ibarra
Reacted by Trevor Clarke, Tihomir Valkanov, Karuppiah Natarajan, W Kristianto, Chris Brooks, xo corvus 🏳️⚧️, Angel S. Moreno, Igor Padoim, Phanindhar, Hamurabi Araújo and 10 more
Reacted by alang, Rodolfo Freire, David Gyori, Diego Stiehl, Natesh Bhat, sapirme, Alistair Smith and Juan Ibarra
@ChiperSoft, Where should I put the jquery.js file to get require('jquery') working? I've tried to put it at the same level as package.js and main.js but the runtime doesn't seem to pick it up.
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
Reacted by Sonal Dubey, Adam Larner, IC Rainbow, Igor Padoim, pharaoh2012, i42pavar, Festus Adeboye, Martin Kinoo, Michael Bukachi, Patrick Murray and 1 more
If your app does not need node-integration, add "node-integration": false to your BrowserWindow options. In this case module.exports is not available, jQuery works like expected.
Reacted by Monish, Sang Dang, daveduchene, Tihomir Valkanov, Yann Bertrand, Leonid Suprun, hhitch, Chris Brooks, William Teder, Simon Jodet and 21 more
Chances are, if you are using jQuery in an Electron App, you are doing something very wrong or at least inefficient.
Reacted by Ismael Bejarano, John Tendik, baconbrad, Julian Poyourow, DCRussianDev, Alexander Rösel, José Chávez, Olivier Voortman, @racascou, Daniel Lizik and 11 more
@drowlands Including 3party libs in Electron seems to be a bad idea. Imagine the update routine, for instance, or chosing a version. @amhoho That's because you need to require jQuery, or modify its init code at the top function - leaving only factory( global );
Here:
( function( global, factory ) {
"use strict";
if ( typeof module === "object" && typeof module.exports === "object" ) {
// For CommonJS and CommonJS-like environments where a proper `window`
// is present, execute the factory and get jQuery.
// For environments that do not have a `window` with a `document`
// (such as Node.js), expose a factory as module.exports.
// This accentuates the need for the creation of a real `window`.
// e.g. var jQuery = require("jquery")(window);
// See ticket #14549 for more info.
module.exports = global.document ?
factory( global, true ) :
function( w ) {
if ( !w.document ) {
throw new Error( "jQuery requires a window with a document" );
}
return factory( w );
};
} else {
factory( global );
}
I my case I load libs via fetch/Promise or xhr, so I have this routine to remove module checks in vendors' libs. @RROrg weird what you're saying
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.jsandmain.jsbut 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:339frankhale 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.
Add loading message to spinner overlay.
kabalage commentedon Mar 17, 2015
If your app does not need node-integration, add
"node-integration": falseto your BrowserWindow options. In this casemodule.exportsis not available, jQuery works like expected.miguelmota commentedon Apr 27, 2015
@kabalage worked wonderfully, thanks!
vrunoa commentedon May 6, 2015
👍
56 remaining items
Bronts commentedon Oct 28, 2016
I resolved this problem with this
and set
if you with
nodeIntegration: true,imorot jQuery like thisreference to
#345
drowlands commentedon Nov 2, 2016
I mean, it seems to be a bad problem, so why not include it in actual Electron? Maybe integrate major JavaScript libraries into Electron?
reneroth commentedon Nov 3, 2016
Chances are, if you are using jQuery in an Electron App, you are doing something very wrong or at least inefficient.
amhoho commentedon Jan 13, 2017
englishextra commentedon Jan 13, 2017
@drowlands Including 3party libs in Electron seems to be a bad idea. Imagine the update routine, for instance, or chosing a version.
@amhoho That's because you need to
requirejQuery, or modify its init code at the top function - leaving onlyfactory( global );Here:
I my case I load libs via fetch/Promise or xhr, so I have this routine to remove module checks in vendors' libs.
@RROrg weird what you're saying
anuxs commentedon Mar 26, 2017
mark
karlhorky commentedon Apr 5, 2017
@kabalage I think the configuration in your post above is out of date. It looks like it should be like this now:
Merge pull request #254 from deepak1556/devtools_dock_state_reimpleme…
Merge pull request #254 from deepak1556/devtools_dock_state_reimpleme…
Fix electron jquery loading issues
souzace commentedon May 12, 2018
On official docs:
https://electronjs.org/docs/faq#i-can-not-use-jqueryrequirejsmeteorangularjs-in-electron
Fix electron jquery loading issues
alotex commentedon Feb 21, 2019
I'm getting
TypeError: Cannot read property 'createElement' of undefinedin webview.
preload script is
omprabhakaran commentedon Sep 12, 2019
if i use this code, it works fine,
but can't able to close the browserwindow by click of top right button.
Fix electron jquery loading issues