Error using Bootstrap & jQuery Packages in ES6 with Browserify

后端 未结 4 1970
滥情空心
滥情空心 2021-02-07 18:16

I\'m trying to use Bootstrap with jQuery. I\'m using Browserify with a Babel transform to compile. I get the following error.

Uncaught ReferenceError: jQuery is          


        
4条回答
  •  南笙
    南笙 (楼主)
    2021-02-07 18:37

    The accepted answer helped me to right track but the final solution for me was a bit shorter so I will post also here.

    // Importing jQuery in ES6 style
    import $ from "jquery";
    
    // We need to expose jQuery as global variable
    window.jQuery = window.$ = $;
    
    // ES6 import does not work it throws error: Missing jQuery 
    // using Node.js style import works without problems
    require('bootstrap');
    

提交回复
热议问题