Library is not defined

The problem

App loads JS library, but still compiler says that:

jQuery is not defined.  

Most people will experience this with jQuery, but I had similar problems with few other libs as well.

The solution

This is caused because library will probably contain something similar to this:

if ( typeof module === "object" && typeof module.exports === "object" ) {
    module.exports = ...
} else ...

This will create problems since library will use module exports to create definition on it, instead of using global object. So even though library is correctly loaded, it will find module (since Electron is using Node.js), and it will put definitions there.

The fix is to delete module, load library and restore module again. This did the trick for me.












Original answer is here (thanks!). You can check related forum thread as well.

About Vjekoslav Ratkajec

Software developer from Zagreb, Croatia. Love programming, running, hiking and biking. Adore nature and animals. Also author of this blog.

Comments