首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >引导:未定义的TypeError:无法读取未定义的属性fn

问引导:未定义的TypeError:无法读取未定义的属性fn
EN

Stack Overflow用户
提问于 2018-07-16 20:56:10
回答 4查看 25.1K关注 0票数 12

我正在尝试用Bootstrap做一个电子应用程序。我收到以下错误消息:

代码语言:javascript
复制
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中的依赖项是:

代码语言:javascript
复制
"dependencies": {
  "bootstrap": "^4.1.2",
  "electron": "^2.0.5",
  "jquery": "^3.3.1",
  "popper.js": "^1.14.3"
}

我的index.html文件是:

代码语言:javascript
复制
<!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>

然后由main.js从电子快速启动加载html文件:

代码语言:javascript
复制
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()
  }
})

我找到的大多数解决方案都告诉我在引导之前导入jQuery,但这已经是我正在做的事情了。

谢谢你的帮助!

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2018-07-19 18:07:38

我找到了解决问题的方法。

我在index.html中添加了一个脚本:

代码语言:javascript
复制
<script src="scripts/script.js"></script>

这是script.js的内容:

代码语言:javascript
复制
window.$ = window.jQuery = require('jquery'); // not sure if you need this at all
window.Bootstrap = require('bootstrap');

我们可以从index.html中删除这些行以避免双重导入:

代码语言:javascript
复制
<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的评论。

票数 17
EN

Stack Overflow用户

发布于 2018-11-04 10:51:06

由于格里福德的回答,我成功地让我的角度&电子应用程序与Bootstrap一起运行。我想在这里贡献的是不需要任何外部文件--您也可以在脚本块中初始化JQuery和Bootstrap:

代码语言:javascript
复制
<script>
  window.$ = window.jQuery = require('jquery');
  window.Bootstrap = require('bootstrap');
</script>

以下版本(电子2.0.7)适用于我:

代码语言:javascript
复制
"bootstrap": "^4.1.3",
"jquery": "^3.3.1",
"popper.js": "^1.14.4"

注意:当由上面的两行初始化时,使用Bootstrap不需要其他脚本集成。另外,您需要的是CSS (在我的例子中是通过angular.json添加到包中)。

票数 5
EN

Stack Overflow用户

发布于 2018-12-31 13:08:07

在我的例子中,我把脚本导入的顺序搞错了。引导导入应该在popper和jquery导入之后进行。

因为引导v4.+依赖于popper.js和jquery

代码语言:javascript
复制
"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"
        ]
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51369979

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档