首页 > 解决方案 > 未捕获的错误:Bootstrap 的 JavaScript 在电子应用程序中需要在 bootstrap.min.js:6 处使用 jQuery

问题描述

我已经构建了一个使用 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。

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

标签: javascriptjquerynode.jsangularelectron

解决方案


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

npm 安装 jquery

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

推荐阅读