0

I have created a simple website and a corresponding javascript file. When I open the site in any browser, it works fine. The script gets executed and there are no errors.

Then I tried to convert my website to a web-app using Electron. For now I didn't change anything, and added only a package.json and a main.js file, as described in Electron's getting started guide.

When opening the app, I can see my website just fine. But there is alsoan error popping up:

ReferenceError: $ is not defined

This comes from my javascript file:

$(document).ready(function() {
  setInterval(doStuff, INTERVAL_MS);
});

So my question is: Why did this code work when I run the site directly in the browser? And why the error when I run it via Electron?

PS: This how my index.html's head looks like. As you can see jQuery is included.

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <!-- Style sheets -->
    <link rel="stylesheet" href="style.css" />

    <!-- External libraries -->
    <script type="text/javascript" src="js/libs/jquery-2.2.0.min.js"></script>
    <script type="text/javascript" src="js/libs/knockout-3.4.0.js"></script>

    <!-- Internal scripts -->
    <script type="text/javascript" src="js/globals.js"></script>
    <script type="text/javascript" src="js/viewModel.js"></script>
    <script type="text/javascript" src="js/util.js"></script>
    <script type="text/javascript" src="js/dummyDataProvider.js"></script>
    <script type="text/javascript" src="js/switcher.js"></script>
    <script type="text/javascript" src="js/main.js"></script>
</head>
Boris
  • 8,551
  • 25
  • 67
  • 120

1 Answers1

0

Append your index.html with the following script and make sure the path is correct for your case:

<script>
window.$ = window.jQuery = require('./js/libs/jquery-2.2.0.min.js');
</script>
Jens Habegger
  • 5,266
  • 41
  • 57