$(...).jstree 不是函数,在 Electron js 中使用 JSTree

$(...).jstree is not a function, using JSTree in Electron js

我正在 python django 使用 jQueryjsTree 构建应用程序。该应用程序在浏览器中正常运行,但是当我为我的项目创建电子应用程序时,它显示

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

我遇到这个错误

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

我还在 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>

来自这里:

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

改变这个:

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

你的功能是错误的。

你不能$=jquery="something"。因此错误

找到答案

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

参考: