0

I have built an electron app that uses Angular framework. Inside 'index.html' file I load bootstrap and jquery. But after electron app is built using electron-packager. I see this error.

Uncaught Error: Bootstrap's JavaScript requires jQuery
    at bootstrap.min.js:6

From previous answers to this question I ensured jquery is loaded first and then the bootstrap. But still I see this error

For ref I have attached the index.html

<!doctype html>
<html lang="en">
    <head>
      <meta charset="utf-8">
      <title>Demo App</title>
      <base href="./">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <link rel="icon" type="image/x-icon" href="favicon.ico">
      <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
    </head>
    <body>
    </body>
   </html>

But If I run the same as web app in browser, I don't see this error. Note : As you see in the index.html, I am using CDN for jquery and bootstrap.

Any thoughts or suggestion would really be appreciated.

2 Answers 2

2

Instead of using the CDN library, I'd like to recommend using the jQuery npm package on Electron.

npm install jquery

<script>
  window.$ = window.jQuery = require("jquery");
</script>
Sign up to request clarification or add additional context in comments.

9 Comments

Thanks tpikachu, I tried to load bootstrap and jquery locally instead of CDN but this as well didn't resolve this error
Have you installed jquery package?
@karansys to use my solution you need to enable the nodeIntegration while you are creating browserWIndow
By enabling the nodeIntegration you can use require() on the renderer. As this require is Node API not browser API.
Anyhow, in my experience. to define a new browser property manual config was the best choice especially for jQuery
|
0

Add the bellow script in your html file:

<!-- Insert this line above script imports  -->
<script>
  if (typeof module === 'object') {    window.module = module; module = undefined;  }
  </script>

Then add scripts:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.0/jquery.min.js" integrity="sha256-xNzN2a4ltkB44Mc/Jz3pT4iU1cmeR0FkXs4pru/JxaQ=" crossorigin="anonymous"></script>

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>

then add the bellow:

<!-- Insert this line after script imports -->
<script>if (window.module) module = window.module;</script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.