-
Notifications
You must be signed in to change notification settings - Fork 461
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
N-api builds not cross runtime with Electron on windows #269
Comments
There have been some discussions with the electron team but there are additional factors that mean this likely require the electron team to do work as well. The main issue I believe is that electron uses different versions of V8 than what may have been used with Node.js (if I remember correctly to match the version of chrome used), and therefore the implementation of the N-API methods that are exported might have to be tweaked for a version of V8 that was never shipped with Node. Not quite sure why it would be Windows only though. Probably best to loop in @groundwater into the discussion to get the full picture. |
It seems like to me that its related to the node.lib file that gets linked into the build on windows. If you build a module for electron 2.0.0 runtime the build gets linked to this library: https://atom.io/download/atom-shell/v2.0.0/x64/node.lib However the version of node.lib that gets linked in for node builds is https://nodejs.org/dist/v8.9.3/win-x64/node.lib. Even though electron 2.0.0 is backed by node version 8.9.3, these are clearly different as they are different sizes. This would explain why it only happens on windows and why the error mentions DLL initialization. The electron runtime is looking for symbols that aren't there in the node runtime. With the n-api environment, it would seem to me that even if electron used slightly different V8 headers it would still be compatible (as we see on Unix). It' once these node.lib libraries are aligned the runtimes will probably be compatible on windows as well. Update: This also fails if you build for electron and try running in the node enviroment.
Once again, only on windows |
https://blogs.msdn.microsoft.com/junfeng/2006/11/20/debugging-loadlibrary-failures will help you figure out the root cause here - the short version is:
|
@paulcbetts |
Any update on the discussion here? |
Running into the same problems with n-api builds done against Node.js not working with Electron on windows. |
Still no update? |
@codebytere this is the issue we mentioned at the summit. |
@here Hi → C:\Users\Ignazio\Desktop\4M\BRIDGE\4mantis\bridge\bridgeElectron\BridgeReact\build\Debug\addon.node the addon is never find -------- EDITED |
@nodejs/platform-windows Any ideas here? |
I have a hunch it's related to nodejs/node-gyp#1566. |
@codebytere any chance you've been able to look at this? |
Although I guess worth waiting until @refack confirms if it is nodejs/node-gyp#1566 or not. |
No, nodejs/node-gyp#1566 did not solve this. |
Is there a solution or workaround for this? We are building an Electron app that runs on Mac and Windows and needs to call a C++ lib which is packaged as a napi module. Everything works perfectly on the Mac, but we get this problem on Windows. This is a bit of a disaster for us if this doesn't work! |
@codebytere would you be able to help us better understand the problem and what options there are for improving this when using modules with Electron? |
I have managed to work around this problem. I'm building my native module using cmake-js, here is what I did:
The problem is that cmake-js links the native module directly to node.exe (you will see this if you open it in Dependency Viewer). When we try and run this in Electron, node.exe isn't available so LoadModule() fails. What the hook does is look for a request to load node.exe and intercept it. If node.exe is available then fine, it lets it through. If not it looks for node.dll (which will work for Electron 3.x) or failing that returns the hosting .exe (which I think will be needed for Electron 4.x). Hope this helps someone else looking to solve this problem! |
Thanks @stevebaxter , The above solution worked for us. |
@digitalinfinity could you possibly take a look at this since it affects Windows and help the N-API understand the problem and any way forward? |
Does this only apply to Windows (and not any other platform)? |
@vweevers I'm pretty sure it's Windows-specific, because on Windows the source of the symbols required by the native addon matters. If the native addon specifies that the symbols have to come from "node.exe", then the loader will only use "node.exe" to resolve the symbols. "node.dll" will not satisfy the requirement. However, the workaround above presented by @stevebaxter should do the trick. |
I think that's correct, AFAIK it's only on Windows that the symbols are exported from different DSOs depending on how everything is linked (or at least this hasn't been a problem on macOS). |
The right way to do this on Windows is probably to repackage node.exe into node.exe (a small executable that just acts as a command-line handler for node.dll), and node.dll (the main DLL that exports all the symbols). This way, NAPI modules would always link to node.dll, executables that use node (e.g. Electron) would also link to node.dll. This might be too big a change for the node team though, so my workaround above could also be incorporated somehow. |
Yes, I've confirmed that with tests. I could not reproduce the issue though on Windows with Electron 4, only Electron 3. |
@codebytere was there something changed in electron4 that would have helped on this front? |
BTW that's what |
It may be a separate issue. I get the
|
Does anyone know if this has been resolved? |
On Electron >=4 I've seen no issues (and I gave up on Electron 3). |
@codebytere do you think this is resolved and can be closed? |
Closing as non-reproducible on currently supported versions of Electron (v6 and above) |
I am getting
Reproducible with |
I see that you were able to resolve this issue in your project here 126 Please can you share with us, what was the exact solution? |
I added a gist of my CMakeLists.txt file I use for N-API projects (including The weird thing which caused problems in my project was the following: The project contains a rather old version of Electron which is used to run UI tests for my project (no time to update yet). My workaround for this problem was to move dependencies required for tests to a separate sub-package so they wont be installed on builds. Still sounds strange to me and I'm still not 100% sure about the root cause of this behaviour. Best regards Simon |
Can anyone help to read this issue electron/electron#27205 |
I was led to believe that the new n-api was not only going to be compatible across all node runtimes, but also going to be compatible when building a native module for node vs building for electron.
If you build the basic hello-world example for n-api found here, the
addon.node
file cannot be required when running from the electron runtime. I get the following error:I set up a basic test here:
https://github.com/jpkolbush/napi-test
Steps to reproduce:
This is only an issue on Windows, does not appear on Unix.
The text was updated successfully, but these errors were encountered: