2

I'm building an app in python django using the jQuery and jsTree. The app is working the browser properly, but when I create the electron app for my project it's showing that

$(...).jstree is not a function.

I am getting this error

Uncaught Error: Cannot find module 'jquery'
    at Module._resolveFilename (module.js:485:15)
    at Function.Module._resolveFilename (/usr/local/lib/node_modules/electron/dist/resources/electron.asar/common/reset-search-paths.js:35:12)
    at Function.Module._load (module.js:437:25)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at http://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.5/jstree.min.js:2:146
    at http://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.5/jstree.min.js:2:175

I also included the following script after the jquery CDN link.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
        <script>
            try {
                $ = jQuery = module.exports;
            } catch(e) {}
        </script>
ponury-kostek
  • 7,824
  • 4
  • 23
  • 31
Ravindra Gupta
  • 1,256
  • 12
  • 42

2 Answers2

1

Found the answer

<!-- 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>

refer : Electron: jQuery is not defined

Ravindra Gupta
  • 1,256
  • 12
  • 42
-2

From this:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
        <script>
            try {
                $ = jQuery = module.exports;
            } catch(e) {}
        </script>

Change this :

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
            <script>
                try {
                    $.jQuery = module.exports;
                } catch(e) {}
            </script>

Your function is wrong.

You cannot do $=jquery="something". Hence the error

Ferrmolina
  • 2,737
  • 2
  • 30
  • 46