-
Notifications
You must be signed in to change notification settings - Fork 183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compiled code only working if bytenode.compileFile is executed using the dev console #47
Comments
Could you please start with something similar to this example? That example uses a very simple logic that can be easily adapted to your needs, and it works with no issues. Let me know if this solves your issue. |
I have used your example to compile all .js files needed for my main process (worked fine). My problem is, that I'm trying to compile the .js files needed for my render process. |
I guess your problem is that you are trying to run your compiled code inside the browser v8 engine, not node v8 engine. The compiled code depends on the APIs that node exposes, so without them it won't run. So, if we have a setup like this, it WON'T work after compilation: <!-- index.html -->
<script src="/path/to/jquery.js"></script>
<script>
const bytenode = require('bytenode');
require('./compiled-file.jsc');
</script> // compiled-file.js
$(document).ready(function() {
$("#target1").css("color", "red");
}); If you want to make it work, you have to use a setup like this: <!-- index.html -->
<script src="/path/to/jquery.js"></script>
<script>
const bytenode = require('bytenode');
require('./compiled-file.jsc')(document, jQuery); // or you can pass the window object itself, or whatever suits your needs.
</script> // compiled-file.js
module.exports = function(document, $) {
$(document).ready(function() {
$("#target1").css("color", "red");
});
} |
This didn't fix my issue. It might be worth pointing out, that my BrowserWindows is using |
Could you please provide a minimal app that reproduce the problem? |
I have uploaded an example to https://github.com/paulr113/bytenode_bug_example. Im pretty sure setTimeout is causing the crash. |
I can reproduce the error. |
Do you have any idea why this is happening? |
Still investigating... |
I looks like the issue isn't related to setTimeout but to async arrow functions in general. document.getElementById("testBtn").onclick = (ev) => {
document.getElementById("testP").innerHTML = "Before delay"
delay(1000).then(() => {
document.getElementById("testP").innerHTML = "After delay"
})
} This code works aswell: document.getElementById("testBtn").onclick = async function (ev) {
document.getElementById("testP").innerHTML = "Before delay"
await delay(1000);
document.getElementById("testP").innerHTML = "After delay"
} This code will result in a crash: document.getElementById("testBtn").onclick = async (ev) => {
document.getElementById("testP").innerHTML = "Before delay"
await delay(1000);
document.getElementById("testP").innerHTML = "After delay"
} delay(): function delay(delay) {
return new Promise((resolve, reject) => {
setTimeout(() => {
return resolve();
}, delay)
})
} |
Thank you for your analysis. I added this to the list of know limitations. |
I have made a new pull request (#49 ) which fixes the issue. |
@OsamaAbbas So, there is no work around for this other than not using async arrow functions? |
Check the pull request by paulr113 (#49), he managed to achieve what you are looking for by using babel. |
Is there an open electron issue that I can follow for this? |
I'm running into a very strange issue while using bytenode to compile the .js files of my Electron app.
I have a compile.js file, which will compile all my code into bytecode. If i try to use it by running require("./compile") from any .js file within the render process the compiled code won't work and gives me an error message. If I on the other hand run
require("./compile")
from the dev tools console the compiled code works just fine.compile.js:
Error message:
The text was updated successfully, but these errors were encountered: