1

I am developing a desktop app with Electron and Angular2 (using Angular-Cli).

I wanted to use Bootstrap so in my angular-cli.json, I added the needed script files to apps[0].scripts like the following:

  "scripts": [
    "../node_modules/jquery/dist/jquery.min.js",
    "../node_modules/bootstrap/dist/js/bootstrap.min.js",
    "../node_modules/toastr/build/toastr.min.js"
  ],

When I run the app in web (using ng serve), everything is working fine. But when I run the app with Electron(ng build first, and run Electron from /dist), I encountered the following error: Uncaught Error: Bootstrap's JavaScript requires jQuery. Angular 2 parts are working fine, routing is working, views are rendered correctly, etc.

When I investigated scripts.bundle.js, those 3rd party libraries are included. But Bootstrap codes are before JQuery. Is that the reason why I am seeing the error with Electron?

Iris
  • 11
  • 1
  • Jquery has a particular way to be used in Electron, maybe that's your problem. In electron jquery must be injected using `require()` – Paulo Galdo Sandoval Oct 24 '16 at 06:43
  • 1
    Thanks for the insight. Your response lead me to another post that helped me solve the issue. http://stackoverflow.com/questions/32621988/electron-jquery-is-not-defined – Iris Oct 24 '16 at 15:25

2 Answers2

2
   <script>
    try {
        window.nodeRequire = require;
        delete window.require;
        delete window.exports;
        delete window.module;
    } catch (e) {
    }
</script>

add this into index.html

dongsj
  • 31
  • 3
0

For me it worked to install both jquery and @types/jquery and placing them in this order.

"scripts": [
    "../node_modules/jquery/dist/jquery.min.js",
    "../node_modules/bootstrap/dist/js/bootstrap.min.js"
],

~ HTH