Skip to content
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

Not building in electron #205

Closed
MoonBarc opened this issue Sep 4, 2020 · 10 comments
Closed

Not building in electron #205

MoonBarc opened this issue Sep 4, 2020 · 10 comments

Comments

@MoonBarc
Copy link

MoonBarc commented Sep 4, 2020

Hi!
I'm trying to make a 3D game in javascript, and I'm currently using Three.js and Electron. I was trying to use this with electron, and it installs properly, however when I go into the devtools, it says

The module was compiled against a different Node.js version using
NODE_MODULE_VERSION 83. This version of Node.js requires
NODE_MODULE_VERSION 82. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).

and when I try to build it using the electron version, it spits out a bunch of errors. I have tried the electron branch too, with no avail (it's old so i didn't really expect it to work anyway lol)

Thanks!

@laverdet
Copy link
Owner

laverdet commented Sep 4, 2020

We have to wait for Electron to update to nodejs v14.x before isolated-vm will (maybe) be compatible. That's expected some time in November.

@MoonBarc
Copy link
Author

MoonBarc commented Sep 4, 2020

Can I use an old version of isolated-vm and electron for the time being?

@laverdet
Copy link
Owner

laverdet commented Sep 4, 2020

I understand electron 2.0.x may work with isolated-vm 1.x, see #132. If you go down that route be sure you're reading the documentation for v1 https://github.com/laverdet/isolated-vm/tree/v1

@MoonBarc
Copy link
Author

MoonBarc commented Sep 8, 2020

Does the node 14 branch of electron work? Or is that still in development...? Old electron doesn't have some of the APIs that I need.

@laverdet
Copy link
Owner

laverdet commented Sep 8, 2020

It might work. I contributed nodejs/node@c712fb7 with the intention of making isolated-vm more interoperable with Electron and nodejs. This change was picked up in nodejs v14 so once that's in Electron theoretically isolated-vm will work.

Even with this you would need to fork a new process with ELECTRON_RUN_AS_NODE and have a non-renderer Electron process [non-Chromium] managing extra isolates. The way v8 is designed it turns out that implementing isolated-vm from within Chrome (or Electron) is really hard. This is also why you can't use worker_threads in Electron: electron/electron#18540.

My suggestion is to invoke child_process.fork from Electron to open a communication channel with a plain nodejs instance:

const { fork } = require('child_process');
const proc = fork('/path/to/node', ['entry.js'], {
  stdio: ['pipe', 'pipe', 'pipe', 'ipc']
});
proc.send('hello');
proc.on('message', message => console.log(message));

You could then communicate with the subprocess using the standard nodejs message passing API. This subprocess would be allowed to use isolated-vm.

@laverdet
Copy link
Owner

laverdet commented Sep 8, 2020

Also I tried to build the nodejs-v14 branch of Electron using the instructions they provided and ran into some errors halfway through the build. I'm sure that rabbit hole runs deep so I stopped there.

@MoonBarc
Copy link
Author

MoonBarc commented Sep 9, 2020

Thank you for the info!
What is ELECTRON_RUN_AS_NODE? Is it just an environment variable that I set?

@laverdet
Copy link
Owner

It's an environment variable that runs the process with node as the "platform" instead of Chromium. It gets set automatically in the child process when you run child_process.fork from Electron. I think you can set it in the environment but I'm not totally sure how the Chromium renderer and the node process interoperate.

@MoonBarc
Copy link
Author

Can confirm that Electron 11 beta works with isolated vm! 🎉

@laverdet
Copy link
Owner

That's surprising because electron v11.x corresponds to nodejs v12.x which wouldn't have the required platform changes. Could you take a look again and confirm that this is working as expected?

I actually was able to get isolated-vm working on electron-nightly with some minor modifications so it does look like we have a path forward very soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants