Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve error "Cannot set property 'emulateTransitionEnd' of undefined" in Bootstrap node.js app?

I created Node.js application from scratch and I have added in app.js.

global.jQuery = require('jquery'); 

After that it gives me error as below:

/home/yojna/web/node_modules/bootstrap/js/transition.js:36
  $.fn.emulateTransitionEnd = function (duration) {
                        ^
    TypeError: Cannot set property 'emulateTransitionEnd' of undefined
    at /home/yojna/web/node_modules/bootstrap/js/transition.js:36:29
    at Object.<anonymous>(/home/yojna/web/node_modules/bootstrap/js/transition.js:59:2)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> 
    (/home/yojna/web/node_modules/bootstrap/dist/js/npm.js:2:1)
    at Module._compile (module.js:456:26)
    yojna@yojna-Inspiron-7520:~/web$ 
like image 611
yojna Avatar asked Jun 26 '15 07:06

yojna


3 Answers

NPM is made to include server-side libraries. To include client-side libraries such as bootstrap or jquery, you shoud use Bower instead.

I've done this in an expressjs app :

  1. Create a .bowerrc file and write the following lines :

    {
      "directory" : "public/components"
    }
    
  2. Download bootstrap and jquery with Bower :

    bower install bootstrap
    
  3. Then, define your public folder to be static in your app.js file :

    app.use(express.static(__dirname + '/public'));
    
  4. Finally, add the script tag in your view (I'am using Jade here) :

    script(src='components/jquery/dist/jquery.min.js')
    script(src='components/bootstrap/dist/js/bootstrap.min.js')
    
like image 199
pjehan Avatar answered Nov 07 '22 17:11

pjehan


Try declare dollar sign variable:

global.jQuery = global.$ = require('jquery'); 
like image 36
jcubic Avatar answered Nov 07 '22 18:11

jcubic


I had this problem, and it was because I had included "bootstrap" in my vendor webpack 2 config but was using:

require("bootstrap-loader");

So the browser couldn't properly find the bootstrap-loader package.

like image 2
Ryan Shillington Avatar answered Nov 07 '22 17:11

Ryan Shillington