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

Work both with node and electron #144

Closed
eric-burel opened this issue May 23, 2017 · 6 comments
Closed

Work both with node and electron #144

eric-burel opened this issue May 23, 2017 · 6 comments

Comments

@eric-burel
Copy link

Hi,

I use zeromq in a an electron app, so I rebuilt zeromq according to the command given in the docs:
npm rebuild zeromq --runtime=electron --target=1.6.1

But, well, now it's broken for node. When running jest, it complains that Module version mismatch. Expected 48, got 53., 53 being the Electron version, while 48 corresponds to my Node version.

This is annoying for setting up a correct development environment. I do not seem to be the first to meet this issue, but I found no solution.

To my mind, the module version should only be checked against node version, not eletron version, so that if I use the same version of node as electron I should not see this issue. To sum it up:

Today I got this:
I use Electron version : 53 / I use Node version 48 ===> mismatch error
But I should have this instead:
I use Electron version 53 ; Electron uses Node version 48 / I use Node version 48 ===> no mismatch error

Is that doable ?

@rgbkrk
Copy link
Member

rgbkrk commented May 23, 2017

Native modules have to be built for the Application Binary Interface (ABI) of the node runtime. By necessity, since the V8 headers don't match exactly between electron and node, they have different ABI numbers. You'll notice a period of where node.js skipped numbers because Electron was using those numbers. In short, it's impossible to run a native binary across two different ABI versions of node.

To answer your question, there are a few options:

  • electron-builder can manage native binaries for you cleanly, making sure to rebuild as necessary. This is what we use in nteract
  • Target your tests using ELECTRON_RUN_AS_NODE=true electron as your node runtime
  • use electron-mocha

@eric-burel
Copy link
Author

Thanks for the ELECTRON_RUN_AS_NODE tip and your explanations, I understand better.
I think this is the easiest solution, though it might need to fork jest-cli a little to replace node by electron.

@webhaoying
Copy link

the same issue resolved by this:

npm install //install the dependencies  first
npm install --save-dev electron-rebuild //make sure you have install the electron-rebuild(win and linux)

every time you run 'npm install',you have to run this:

./node_moudles/.bin/electron-rebuild  

On window, if you have trouble, you can try this :

.\node_moudles\.bin\electron-rebuild.cmd

@ronkorving
Copy link

ronkorving commented Sep 25, 2017

In the future, we should probably update node-zeromq to use N-API so it can be ABI stable across multiple versions of Node.

@eric-burel
Copy link
Author

Hi, just to tell that I managed to launch Jest using electron: jestjs/jest#3698
This makes this issue less important, because I can test in the correct environment. Thanks for the help!

@rolftimmermans
Copy link
Member

The latest 6.0 beta release now uses N-API and should work in Electron 3+ out of the box. It would be great if you could try it out! The new version has a new API that addresses some fundamental issues with the previous API, but it does include a compatibility layer that should make upgrading easier. See #189 for the reasoning behind the new API.

If you run into any problems feel free to report it here or in a new issue.

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

5 participants