我正在尝试使用Bootstrap开发一个Electron应用程序。我收到此错误消息:
Uncaught TypeError: Cannot read property 'fn' of undefined
at setTransitionEndSupport (bootstrap.js:122)
at bootstrap.js:199
at bootstrap.js:201
at bootstrap.js:9
at bootstrap.js:10
我在package.json中的依赖项是:
"dependencies": {
"bootstrap": "^4.1.2",
"electron": "^2.0.5",
"jquery": "^3.3.1",
"popper.js": "^1.14.3"
}
我的index.html文件是:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Release Management Report</title>
</head>
<body>
<div class="container">
<h1>Bootstrap Test</h1>
<p>
We are using node
<script>document.write(process.versions.node)</script>, Chrome
<script>document.write(process.versions.chrome)</script>, and Electron
<script>document.write(process.versions.electron)</script>.
</p>
</div>
<script src="node_modules/jquery/dist/jquery.min.js"></script>
<script src="node_modules/popper.js/dist/umd/popper.min.js"></script>
<script src="node_modules/bootstrap/dist/js/bootstrap.js"></script>
</body>
</html>
然后从Electron快速入门中的main.js加载html文件:
const { app, BrowserWindow } = require('electron')
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let win
function createWindow() {
// Create the browser window.
win = new BrowserWindow({ width: 800, height: 600 })
// and load the index.html of the app.
win.loadFile('index.html')
// Open the DevTools.
win.webContents.openDevTools()
// Emitted when the window is closed.
win.on('closed', () => {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
win = null
})
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow)
// Quit when all windows are closed.
app.on('window-all-closed', () => {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', () => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (win === null) {
createWindow()
}
})
我找到的大多数解决方案都告诉我在Bootstrap之前导入jQuery,但这已经是我正在做的事情。
感谢您的帮助!
答案 0 :(得分:9)
我在index.html中添加了一个脚本:
<script src="scripts/script.js"></script>
这是script.js的内容:
window.$ = window.jQuery = require('jquery'); // not sure if you need this at all
window.Bootstrap = require('bootstrap');
我们可以从index.html删除这些行以避免重复导入:
<script src="node_modules/jquery/dist/jquery.min.js"></script>
<script src="node_modules/popper.js/dist/umd/popper.min.js"></script>
<script src="node_modules/bootstrap/dist/js/bootstrap.js"></script>
我在以下位置找到了此解决方案:https://github.com/understrap/understrap/issues/449, 根据karo1915的评论。
答案 1 :(得分:3)
就我而言,我的脚本导入顺序错误。引导程序导入应该在popper和jquery导入之后。
因为Bootstrap v4。+以上版本取决于popper.js和jquery
"scripts": [
"./node_modules/jquery/dist/jquery.slim.min.js",
"./node_modules/popper.js/dist/umd/popper.min.js",
"./node_modules/bootstrap/dist/js/bootstrap.min.js"
]
答案 2 :(得分:2)
感谢Griford的回答,我设法使我的Angular&Electron应用程序与Bootstrap一起运行。我在这里想要做的就是不需要外部文件-您也可以在脚本块中初始化JQuery和Bootstrap:
import java.text.SimpleDateFormat;
import java.util.Date;
public class Main {
public static void main(String[] argv) throws Exception {
Date date = new Date();
SimpleDateFormat simpDate;
simpDate = new SimpleDateFormat("kk:mm:ss");
System.out.println(simpDate.format(date));
}
}
这适用于以下版本(Electron 2.0.7):
<script>
window.$ = window.jQuery = require('jquery');
window.Bootstrap = require('bootstrap');
</script>
注意:通过以上两行初始化时,使用Bootstrap不需要其他脚本集成。另外,您唯一需要的就是CSS(就我而言,是通过angular.json添加到捆绑包中的)。
答案 3 :(得分:0)
引导程序4.1.3
出现相同的错误,并且我确定脚本顺序正确,并且将jquery放在引导程序之前。
由于我通过tampermonkey
属性将这些脚本加载到@require
脚本(用于管理可以修改当前网页的第三方脚本的浏览器加载项)中,因此很难在jquery加载之间注入代码和引导加载。
更改为引导程序的先前版本3.3.7
可解决该错误。等待下一个引导程序版本将解决此问题。