【发布时间】:2018-12-31 21:08:07
【问题描述】:
我正在尝试使用 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,但这已经是我正在做的事情了。
感谢您的帮助!
【问题讨论】:
-
您能告诉我们您的 html 文件是如何加载的吗?
-
@Thaadikkaaran 是的,我使用了电子快速入门中的 main.js,我已经在问题中添加了它
-
我有同样的问题,使用完全相同的依赖项和版本,但没有使用电子。我正在从 Rails 模板加载。
-
@nuno 你好,我找到了一个适合我的解决方案。我将其添加为答案。也许它也对你有用。
-
嗨!格里福德!该问题似乎与库加载顺序有关。我没有使用与使用 Rails 资产管道完全相同的解决方案,但也设法修复了它。基本上 jquery 必须在 bootstrap 之前加载,我以为我在做但实际上不是。谢谢分享!
标签: jquery node.js bootstrap-4 electron