我目前正在使用 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>
/bootstrap/static/jquery.min.js
加载。nodeIntegration = true
和 contextIsolation = false
。$ is not defined
错误不会显示并正常工作。我们将不胜感激一些帮助!
您可以将其导入到 body 元素的底部,如下所示::
<body>
<!-- Other body content -->
<script>window.$ = window.jQuery = require('{PATH_OF_JQUERY}/jquery-3.2.1.min.js');</script>
</body>