Electron 中的 jQuery 错误:“$ 未定义”

问题描述 投票:0回答:1

我目前正在使用 pyinstaller 构建 Flask Web 应用程序,并且我一直在尝试让它在 Electron 上运行。该项目使用 jQuery 和 Bootstrap 以及其他几个库。

问题是我遇到了两个错误:

TypeError: Cannot read properties of undefined (reading 'fn')
(
$.fn.emulateTransitionEnd = transitionEndEmulator
)

ReferenceError: $ is not defined

这使我无法使用网站的某些功能。

我尝试过的事情:

<!-- Insert this line above script imports  -->
<script>if (typeof module === 'object') {window.module = module; module = undefined;}</script>

<!-- normal script imports etc  -->
<script src="scripts/jquery.min.js"></script>    
<script src="scripts/vendor.js"></script>    

<!-- Insert this line after script imports -->
<script>if (window.module) module = window.module;</script>
  • 确保 jQuery 加载。它从
    /bootstrap/static/jquery.min.js
    加载。
  • 添加行
    nodeIntegration = true
    contextIsolation = false
  • 运行 Flask 可执行文件并在浏览器上打开网站时,
    $ is not defined
    错误不会显示并正常工作。
  • 检查了 jQuery 和其他脚本的导入顺序。

我们将不胜感激一些帮助!

jquery flask pyinstaller
1个回答
0
投票

您可以将其导入到 body 元素的底部,如下所示::

<body>
    <!-- Other body content -->

    <script>window.$ = window.jQuery = require('{PATH_OF_JQUERY}/jquery-3.2.1.min.js');</script>
</body>
© www.soinside.com 2019 - 2024. All rights reserved.