首页 > 解决方案 > $(...).jstree 不是函数,在 Electron js 中使用 JSTree

问题描述

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

$(...).jstree 不是一个函数。

我收到此错误

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 链接之后包含了以下脚本。

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

标签: javascriptjqueryelectronjstree

解决方案


找到了答案

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


推荐阅读