javascript - 未捕获的错误: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。
任何想法或建议将不胜感激。
解决方案
我建议不要使用 CDN 库,而是使用 Electron 上的 jQuery npm 包。
npm 安装 jquery
<script>
window.$ = window.jQuery = require("jquery");
</script>
推荐阅读
- oracle - spring boot - 尽管出现 oracle 错误,应用程序仍会启动
- corda - Corda 模板 kotlin gradle 子项目
- html - 如何使用 rel=preload 预加载素材图标?
- grails - grails 3运行命令不起作用
- sql-server - 在 SQL Server 中将时间格式从 3.5 转换为 3:30
- java - 在 Lucene 中索引多级 JSON 对象
- python - 了解父级属性设置器的继承
- c++ - Eigen + MKL 对于矩阵乘法比 Matlab 慢
- wordpress - 标题未显示在前端 - 古腾堡
- javascript - 为对象中的所有成员调用 setTimeout() - 从不调用第一个成员,并调用第二个成员。为什么?