Repository navigation
Closed
Description
- Node Version: 8.9.4
- Platform: Windows
- Compiler: MSVC 15
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:
A dynamic link library (DLL) initialization routine failed.
\\?\C:\Users\kelannen\source\napi-test\build\Release\addon.node
Error: A dynamic link library (DLL) initialization routine failed.
\\?\C:\Users\kelannen\source\napi-test\build\Release\addon.node
at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:172:20)
at Object.Module._extensions..node (module.js:671:18)
at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:172:20)
at Module.load (module.js:561:32)
at tryModuleLoad (module.js:504:12)
at Function.Module._load (module.js:496:3)
at Module.require (module.js:586:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (C:\Users\kelannen\source\napi-test\test.js:2:15)
at Object.<anonymous> (C:\Users\kelannen\source\napi-test\test.js:6:3)
at Module._compile (module.js:642:30)
at Object.Module._extensions..js (module.js:653:10)
at Module.load (module.js:561:32)
at tryModuleLoad (module.js:504:12)
at Function.Module._load (module.js:496:3)
at Module.require (module.js:586:17)
at require (internal/module.js:11:18)
at C:\Users\kelannen\source\napi-test\node_modules\mocha\lib\mocha.js:253:27
at Array.forEach (<anonymous>)
at Mocha.loadFiles (C:\Users\kelannen\source\napi-test\node_modules\mocha\lib\mocha.js:250:14)
at Mocha.run (C:\Users\kelannen\source\napi-test\node_modules\mocha\lib\mocha.js:577:10)
at Object.run (C:\Users\kelannen\source\napi-test\node_modules\electron-mocha\mocha.js:54:30)
at App.app.on (C:\Users\kelannen\source\napi-test\node_modules\electron-mocha\index.js:54:13)
at emitTwo (events.js:131:20)
at App.emit (events.js:214:7)
I set up a basic test here:
https://github.com/jpkolbush/napi-test
Steps to reproduce:
npm install
#runs node-gyp configure-build
npm run build
#confirms that the module can be included with node runtime
node test.js
#requires the node module while running electron-mocha, this command will fail
npm run electron-test
This is only an issue on Windows, does not appear on Unix.
Reacted by Refael Ackermann and friksa
Metadata
Metadata
Assignees
Labels
No labels
Activity
mhdawson commentedon May 14, 2018
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.
jpkolbush commentedon May 15, 2018
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
anaisbetts commentedon May 15, 2018
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:
jpkolbush commentedon May 15, 2018
@paulcbetts
I assume you mean running node.exe under WinDbg since thats the process I'm trying to load the module with. It was just compiled against the headers (and node.lib) provided from electron.
mhdawson commentedon Jun 14, 2018
Any update on the discussion here?
mafintosh commentedon Oct 11, 2018
Running into the same problems with n-api builds done against Node.js not working with Electron on windows.
only do electron napi builds for now, re nodejs/node-addon-api#269
BotellaA commentedon Oct 12, 2018
Still no update?
mhdawson commentedon Oct 16, 2018
@codebytere this is the issue we mentioned at the summit.
NEVADV commentedon Nov 5, 2018
@here Hi
i face the same problem, my addon build with node doesn't work with the version of node in Electron, i tested with many version of node and electron, and he never worked, i tested with electron-rebuild and he never work even electron find the good header when i done :
this "node-gyp rebuild --target=3.0.6 --arch=x64 --dist-url=https://atom.io/download/atom-shell"
with many different target to map my version of electron, but i got always the same messsage
"bindings.js:93 Uncaught Error: Could not locate the bindings file. Tried:
→
C:\Users\Ignazio\Desktop\4M\BRIDGE\4mantis\bridge\bridgeElectron\BridgeReact\build\addon.node
→ C:\Users\Ignazio\Desktop\4M\BRIDGE\4mantis\bridge\bridgeElectron\BridgeReact\build\Debug\addon.node
→ C:\Users\Ignazio\Desktop\4M\BRIDGE\4mantis\bridge\bridgeElectron\BridgeReact\build\Release\addon.node
"
the addon is never find
-------- EDITED
finally i tested with a new simple electron app ( the sample quick-start from electron site) and it work with the use of electron-rebuild and this command
"node-gyp rebuild --target=3.0.4 --arch=x64 --dist-url=https://atom.io/download/atom-shell"
make sure you target the right target ( here i target the version 3.0.4 of electron )
hope this help !
addaleax commentedon Nov 10, 2018
@nodejs/platform-windows Any ideas here?
refack commentedon Nov 10, 2018
I have a hunch it's related to nodejs/node-gyp#1566.
I'm verifying now.
mhdawson commentedon Nov 12, 2018
@codebytere any chance you've been able to look at this?
mhdawson commentedon Nov 12, 2018
Although I guess worth waiting until @refack confirms if it is nodejs/node-gyp#1566 or not.
refack commentedon Nov 13, 2018
No, nodejs/node-gyp#1566 did not solve this.
8 remaining items
stevebaxter commentedon Mar 30, 2019
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).
stevebaxter commentedon Mar 30, 2019
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.
vweevers commentedon Mar 30, 2019
Yes, I've confirmed that with tests.
I could not reproduce the issue though on Windows with Electron 4, only Electron 3.
mhdawson commentedon Apr 2, 2019
@codebytere was there something changed in electron4 that would have helped on this front?
refack commentedon Apr 2, 2019
BTW that's what
node-gypdoes by addingwin_delay_load_hook.ccto every addon inhttps://github.com/nodejs/node-gyp/blob/bb8b294ae76ed16d6633344ff06f6dc5d5ddbe02/addon.gypi#L67-L89
/CC @unbornchikken @cmake-js
vweevers commentedon Apr 2, 2019
It may be a separate issue. I get the
A dynamic link library (DLL) initialization routine failederror withnode-gypin fact. To reproduce (pairing Electron 3 withleveldown@5):mafintosh commentedon Apr 30, 2020
Does anyone know if this has been resolved?
vweevers commentedon Apr 30, 2020
On Electron >=4 I've seen no issues (and I gave up on Electron 3).
mhdawson commentedon May 4, 2020
@codebytere do you think this is resolved and can be closed?
codebytere commentedon May 4, 2020
Closing as non-reproducible on currently supported versions of Electron (v6 and above)
bsrdjan commentedon May 12, 2020
I am getting
A dynamic link library (DLL) initialization routine failedwithnode-rfcNAPI module in Electron, on Windows 10. The module works just fine without Electron. Here the configuration:Reproducible with
require('node-rfc')step inpreload.jsofelectron-quick-startexample.yerkeyzet commentedon May 13, 2020
@s1hofmann
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?
s1hofmann commentedon May 13, 2020
@yerkeyzet
I added a gist of my CMakeLists.txt file I use for N-API projects (including
win_delay_load_hook.cc).I'm only considering Electron v4 or higher, so no guarantee for v3 or earlier.
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).
On Windows, my module was not usable with Electron (
Uncaught Error: A dynamic link library (DLL) initialization routine failed...) after runningnpm install && npm run build:release:win. No problems on Linux and macOS.After I dissected the whole project I noticed that as soon as I included the outdated Electron version required for tests in my
devDependencies, the module would no longer work with Electron on Windows. Builds which do not have Electron installed worked fine on Windows as well.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.
Anyways, since N-API builds in combination with Electron seem to not only confuse myself sometimes, I added my findings here.
Best regards
Simon
lilong7676 commentedon Jan 6, 2021
Can anyone help to read this issue electron/electron#27205
@mhdawson Please help...