opal icon indicating copy to clipboard operation
opal copied to clipboard

NodeJS / Electron loading issue

Open mistergibson opened this issue 5 years ago • 2 comments

I have a vexing issue when I attempt to require a javascript file generated by Opal 1.0.3 for electron-builder. I think at this point that it stems from the differences between a browser window javascript environment and that of a node.js main.js environment. Un-minified the file will not even compile and throws an error involving babel --> the cure is to minify it and babel is happy (See this issue: https://github.com/opal/opal/issues/2118 ). The issue: after loading and running Opal produced code the app just simply quits and any logic below the require call is not even run. Oh the Ruby script will run, but it is the only thing that runs, and then the app quits. if I comment out the requirement - the app runs fine, I get a test window and all is well. I've tried the following to load the javascript file:

const something = require("some-file.js"); require("some-file.js"); require("some-file.js)(); global.Opal = require("some-file.js"); global.Opal = require("some-file.js")();

Is this simply pilot error? Is there a special way to load these sorts of files? I was wondering also about global setting policy differences. If I set the global in main.js I think it will work, but I do not thing it will allow a global to be set in a sub-requirement. I'm not totally sure on this, but I have a hunch. If this is the case I would lobby for a new opal command-line build option: --object-only that will produce code such that the Ruby script does get run, but the entire function enclosure avoids setting a global and simply returns itself as Opal object. Then something like "global.Opal = require("some-file.js")();" will work in my main.js even if there is a domain-specific restriction on global value setting within the required files.

Your thoughts?

mistergibson avatar Oct 07 '20 23:10 mistergibson

As far as I know, Node exists once all events have been processed. Something like this should make it stay infinitely:

`setInterval(function() {}, 1000);`

hmdne avatar Oct 12 '20 11:10 hmdne

first you need to compile the file, then run node output.js

sebyx07 avatar Dec 18 '20 16:12 sebyx07