0

I am building a Flask web app using pyinstaller, and I've been trying to get it to work on Electron. The project uses jQuery and Bootstrap along with a couple of other libraries.

The problem is that I've been getting two errors:

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

ReferenceError: $ is not defined

This prevents me from using certain features of the website.

Things I've tried:

<!-- 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>
  • Ensure jQuery loads. It loads from /bootstrap/static/jquery.min.js.
  • Add the lines nodeIntegration = true and contextIsolation = false.
  • When running the Flask executable and opening the website on my browser, the $ is not defined error does not show up and works correctly.
  • Checked the order of imports for jQuery and other scripts.

Some help would be deeply appreciated!

New contributor
Juno C is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
3
  • How did you determine that jQuery is loading?
    – isherwood
    Commented Jul 3 at 20:46
  • When I look at the network tab of the developer console, I can see a GET request for jquery which happens successfully.
    – Juno C
    Commented Jul 4 at 15:24
  • Don't tell me down here. Tell the community in your question. Please take the tour.
    – isherwood
    Commented 2 days ago

1 Answer 1

0

You can import it at the bottom of the body element like this::

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

    <script>window.$ = window.jQuery = require('{PATH_OF_JQUERY}/jquery-3.2.1.min.js');</script>
</body>
1
  • What problem does this solve?
    – isherwood
    Commented 2 days ago

Not the answer you're looking for? Browse other questions tagged or ask your own question.