Hi.
I’ve made some tests with electron (also with electron-packager which actually shows same results) with some large ionic apps we’ve created. Here’s more background for start:
- we’re using generator-m to create new ionic/cordova apps.
- after creating app, we use
gulp build
to pack all external JS libraries into singlevendor.js
and our local libraries (services, controllers etc from angular) intoapp.js
. Everything gets saved intowww/
directory. This is created with usinggulp
task - running the
index.html
in browser works as it should. console in browser doesn’t show any errors whatsoever. - now, I’ve created new Electron project in seperate directory, screenshot as reference:
-
main.js
is exactly how it is on electron website with addedwww/
directory like this:mainWindow.loadUrl('file://' + __dirname + '/www/index.html');
- package.json is just pure:
{
"name" : "your-app",
"version" : "0.1.0",
"main" : "main.js"
}
- running
electron .
command opens Electron with my app, but here are the problems:
#Problem #1#
Uncaught Error: Cannot find module 'promise' (module.js:338)
and I have no idea where that comes from? We’ve tried with npm install
commands and what not, but we don’t have any modules directory, since everything is packed in app.js
and vendor.js
in the first place.
#Problem #2#
If you check screenshot#2 again, you will notice that I’ve manually included PouchDB libraries we’re using. Why is that? Because, if I don’t do that, I get an error that PouchDB is not found or defined. Once again, all these pouch and other libraries are merged in vendor.js
as stated above. Adding files manually to index.html
solves the problem.
But then, we got another bunch of errors for example: _ is not defined
(lowdash lib).
So the question I am having is:
- why cannot Electron use the
vendor.js
which is packed with all libraries? - why are then some libraries found from
vendor.js
and some not? (angular, ionic work, pouch, lowdash not- even though all of them are located invendor.js
) - should I really pack each and single library manually into
index.html
?
This is totally against idea and concept of how our apps are built, since every single browser supports and loads our app.js
and vendor.js
without any problem.
Please help me understand the problem and eventually finding the reason/solution to what is it actually happening.
Thank you and best regards