简体   繁体   English

电子包装器Javascript错误(jQuery)

[英]Electron-packager Javascript Error (jQuery)

I have problems compiling my (first) electron project... 我在编译我的(第一个)电子项目时遇到问题...

I could successfully create the new folder with the compiled app, however, when trying to open the executable a pop-up comes up stating: 我可以使用编译后的应用程序成功创建新文件夹,但是,当尝试打开可执行文件时,弹出窗口显示:

A Javascript Error occured in the main process 主程序中发生Javascript错误

Uncaught Expectation: $ is not defined at....... 未预料到的期望:$的定义没有......。

I have tried this solution but it doesnt change anything. 我已经尝试过这种解决方案,但它不会改变任何东西。

  <!--Hack to fix library not defined (pt. 1)-->
  <script>
    if (typeof module === 'object') {
      window.module = module;
      module = undefined;
    }
  </script>

  <!--Library-->
  <script src="./node_modules/jquery/dist/jquery.js"></script>

  <!--Hack to fix library not defined (pt. 2)-->
  <script>
    if (window.module) module = window.module;
  </script>

Thanks for any help! 谢谢你的帮助!

I'm sorry. 对不起。 I was at work. 我之前在工作。

I solved installing jQuery by npm 我解决了通过npm安装jQuery

npm i jquery --save

And importing by require 并按要求导入

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

You can also download it and inform the directory 您也可以下载它并通知目录

<script type="text/javascript">
    window.$ = window.jQuery = require("path/to/js/jquery-3.2.1.slim.min.js);
</script>

Check in working 签到工作

jQuery的工作

Sorry my bad English. 对不起,我的英语不好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM