Gri*_*ord 11 jquery node.js electron bootstrap-4
我正在尝试用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
Run Code Online (Sandbox Code Playgroud)
我在package.json中的依赖项是:
"dependencies": {
"bootstrap": "^4.1.2",
"electron": "^2.0.5",
"jquery": "^3.3.1",
"popper.js": "^1.14.3"
}
Run Code Online (Sandbox Code Playgroud)
我的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>
Run Code Online (Sandbox Code Playgroud)
然后html文件由Electron快速启动的main.js加载:
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()
}
})
Run Code Online (Sandbox Code Playgroud)
我发现的大多数解决方案告诉我在Bootstrap之前导入jQuery,但这已经是我正在做的事情.
谢谢您的帮助!
Gri*_*ord 15
我在index.html中添加了一个脚本:
<script src="scripts/script.js"></script>
Run Code Online (Sandbox Code Playgroud)
这是script.js的内容:
window.$ = window.jQuery = require('jquery'); // not sure if you need this at all
window.Bootstrap = require('bootstrap');
Run Code Online (Sandbox Code Playgroud)
我们可以从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>
Run Code Online (Sandbox Code Playgroud)
我在以下网址找到了这个解决方案:https://github.com/understrap/understrap/issues/449,来自karo1915的评论.
小智 5
感谢 Griford 的回答,我设法让我的 Angular&Electron 应用程序与 Bootstrap 一起运行。我想在这里贡献的只是不需要外部文件 - 您也可以在脚本块中初始化 JQuery 和 Bootstrap:
<script>
window.$ = window.jQuery = require('jquery');
window.Bootstrap = require('bootstrap');
</script>
Run Code Online (Sandbox Code Playgroud)
这适用于以下版本(Electron 2.0.7):
"bootstrap": "^4.1.3",
"jquery": "^3.3.1",
"popper.js": "^1.14.4"
Run Code Online (Sandbox Code Playgroud)
注意:当由上面两行初始化时,使用 Bootstrap 不需要其他脚本集成。除此之外你唯一需要的是 CSS(在我的例子中是通过 angular.json 添加到包中的)。
小智 5
就我而言,我的脚本导入顺序错误。bootstrap 导入应该在 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"
]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15197 次 |
| 最近记录: |