Electron - jQuery Errors

。_饼干妹妹 提交于 2019-12-10 16:13:10

问题


I'm working on an Electron project, and when attempting to include jQuery, I get this error:

C:\Users\Matthew\Documents\Electron\ElectronProjects\Iris\js\jquery.min.js:4 Uncaught SyntaxError:
C:\Users\Matthew\Documents\Electron\ElectronProjects\Iris\js\jquery.min.js:4 b),b&&a.jQuery===n&&(a.jQuery=Hb),n},b||(a.jQuery=a.$=n),n});jQuery v3.0.0-pre

I'v attempted to use the way that was recommended in the Electron issues page (window.$ = window.jQuery = require('./../js/jquery.min.js');). It always throws this error though.

Any ideas?


回答1:


<script type="text/javascript">
    window.$ = window.jQuery = require(__dirname+'/js/jquery.js');
</script>

I used this for jquery 1.9.1 version its works fine.




回答2:


Looks like adding "node-integration": false to my BrowserWindow constructor fixed it. I'd still like an explanation why I have to do so though :)




回答3:


To answer "why", according to this post: https://github.com/atom/electron/issues/254

"jQuery contains...

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.."



来源:https://stackoverflow.com/questions/30271011/electron-jquery-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!