Bootstrap: Uncaught TypeError: Cannot read property 'fn' of undefined

前端 未结 4 1898
隐瞒了意图╮
隐瞒了意图╮ 2021-02-05 20:21

I am trying to make an Electron application with Bootstrap. I get this error message:

Uncaught TypeError: Cannot read property \'fn\' of undefined
at setTransit         


        
相关标签:
4条回答
  • 2021-02-05 20:49

    Thanks to the answer from Griford I managed to get my Angular&Electron app running with Bootstrap. All I wanted to contribute here is that no external file is needed - you can initialize JQuery and Bootstrap in a script block also:

    <script>
      window.$ = window.jQuery = require('jquery');
      window.Bootstrap = require('bootstrap');
    </script>
    

    This works for me with the following versions (Electron 2.0.7):

    "bootstrap": "^4.1.3",
    "jquery": "^3.3.1",
    "popper.js": "^1.14.4"
    

    NOTE: no other script integration is needed for using Bootstrap when initialized by the two lines above. The only thing you need in addition is the CSS (in my case added to the bundle via angular.json).

    0 讨论(0)
  • 2021-02-05 20:58

    I get same error with bootstrap 4.1.3, and I am sure script order is correct, jquery is placed before bootstrap.

    Because I load these scripts in tampermonkey scripts( a browser add-on to manage third party scripts which can modify current web page ) by the @require attribute, it's hard to inject codes between jquery loading and bootstrap loading.

    Changing to a previous version 3.3.7 of bootstrap solves the error. Waiting for next version of bootstrap would solve this.

    0 讨论(0)
  • 2021-02-05 21:04

    I found a way to solve the problem.

    I added a script in the index.html:

    <script src="scripts/script.js"></script>
    

    and this is the content of script.js:

    window.$ = window.jQuery = require('jquery'); // not sure if you need this at all
    window.Bootstrap = require('bootstrap');
    

    and we can remove these lines from index.html to avoid double import:

    <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>
    

    I found this solution at: https://github.com/understrap/understrap/issues/449, under the comment from karo1915.

    0 讨论(0)
  • 2021-02-05 21:05

    In my case, I had the ordering of the imports of scripts wrong. The bootstrap import should come after the popper and jquery imports.

    Since Bootstrap v4.+ depends on popper.js and 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"
            ]
    
    0 讨论(0)
提交回复
热议问题