【问题标题】:Uncaught Error: Bootstrap's JavaScript requires jQuery at bootstrap.min.js:6, in an electron app未捕获的错误:Bootstrap 的 JavaScript 在电子应用程序中需要在 bootstrap.min.js:6 处使用 jQuery
【发布时间】:2020-11-21 07:01:43
【问题描述】:

我已经构建了一个使用 Angular 框架的电子应用程序。在“index.html”文件中,我加载了 bootstrap 和 jquery。但是在使用电子打包器构建电子应用程序之后。我看到了这个错误。

Uncaught Error: Bootstrap's JavaScript requires jQuery
    at bootstrap.min.js:6

根据之前对该问题的回答,我确保先加载 jquery,然后再加载引导程序。但我仍然看到这个错误

对于参考,我附上了 index.html

<!doctype html>
<html lang="en">
    <head>
      <meta charset="utf-8">
      <title>Demo App</title>
      <base href="./">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <link rel="icon" type="image/x-icon" href="favicon.ico">
      <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
    </head>
    <body>
    </body>
   </html>

但是,如果我在浏览器中运行与 Web 应用程序相同的内容,则不会看到此错误。 注意:正如您在 index.html 中看到的,我将 CDN 用于 jquery 和 bootstrap。

任何想法或建议将不胜感激。

【问题讨论】:

    标签: javascript jquery node.js angular electron


    【解决方案1】:

    我建议不要使用 CDN 库,而是使用 Electron 上的 jQuery npm 包。

    npm 安装 jquery

    <script>
      window.$ = window.jQuery = require("jquery");
    </script>
    

    【讨论】:

    • 感谢 tpikachu,我尝试在本地加载 bootstrap 和 jquery 而不是 CDN,但这也没有解决此错误
    • 你安装jquery包了吗?
    • @karansys 要使用我的解决方案,您需要在创建 browserWIdow 时启用 nodeIntegration
    • 通过启用 nodeIntegration,您可以在渲染器上使用 require()。因为这需要 Node API 而不是浏览器 API。
    • 无论如何,根据我的经验。定义一个新的浏览器属性手动配置是最好的选择,尤其是对于 jQuery
    【解决方案2】:

    在您的 html 文件中添加以下脚本:

    <!-- Insert this line above script imports  -->
    <script>
      if (typeof module === 'object') {    window.module = module; module = undefined;  }
      </script>
    

    然后添加脚本:

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.0/jquery.min.js" integrity="sha256-xNzN2a4ltkB44Mc/Jz3pT4iU1cmeR0FkXs4pru/JxaQ=" crossorigin="anonymous"></script>
    
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
    

    然后添加波纹管:

    <!-- Insert this line after script imports -->
    <script>if (window.module) module = window.module;</script>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-17
      • 2020-02-06
      • 2016-12-14
      • 2016-02-17
      • 2018-01-31
      • 2015-06-01
      • 2018-01-21
      • 2016-08-16
      相关资源
      最近更新 更多