I am struggling with the error:
Uncaught Exception: Error: A dynamic link library (DLL) initialization routine failed."
After some research and debugging, the likely issue is that the node module ffi has not been "rebuilt" for the electron environment. I have tried following the steps at https://github.com/electron/electron/blob/master/docs/tutorial/using-native-node-modules.md to rebuild the package, but method 1, when copied to the letter, didn't work.
Method 2 of "Installing module and rebuilding for Electron" doesn't work because entering ./node_modules/.bin/electron-rebuild.cmd (I'm on Windows) doesn't work- Bash simply says "command not found" and I don't see others with this issue. I've tried even running it from PowerShell in case git bash was causing issues, but I get a similar issue, although I also get an error stating:
At line:1 char:1
+electron-rebuild.cmd
+~~~~~~~~~~~~~~~~~~~
_CategoryInfo : ObjectNotFound: (electron-rebuild.cmd:String) [], CommandNotFoundException
+FullyQualifiedErrorID : CommandNotFoundException
I don't understand method 3 (manually building for Electron) and am hesitant to use it- namely I'm unsure of why there isn't an argument in the manual build command for specifying what package needs to be rebuilt.
I have retried installing Electron Rebuild to the letter per the instructions in https://github.com/electron/electron-rebuild multiple times (npm install --save-dev electron-rebuild) in project folder. It seems to be installed in the correct location.
Why is electron-rebuild not being recognized? What will it take to get ffi installed properly?
I'd also appreciate if someone could point me to some additional places to educate myself on what I might be missing with my conceptualization of this issue. Thanks in advance!
Ok, this works for me:
npm config set msvs_version 2015 --global
{
"name": "stack_ffi",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "electron .",
"rebuild": "electron-rebuild -f -w ffi"
},
"author": "",
"license": "XXX",
"devDependencies": {
"electron": "2.0.2",
"electron-rebuild": "1.7.3"
},
"dependencies": {
"ffi": "2.2.0",
"ref": "1.3.5"
}
}
npm run install
and then npm run rebuild
Notes:
On my first try electron did not install correctly so I have deleted
the ./node_modules/electron folder and ran npm run install
again.
When I tried to use a sqlite3.dll on Windows the online example (https://github.com/node-ffi/node-ffi/blob/master/example/sqlite.js) did
not work. I had to remove the leading "lib" part from the library string: var SQLite3 = ffi.Library('sqlite3', {...}); //was 'libsqlite3'
.
I tested it on node 7.4.0 and 8.0.0. If it fails on your node version
I have the theory that v8::Object::ForceSet
was dropped on later
versions.
I had to ensure that Windows can find my dll's. For example I included the sqlite3 x64 dlls by adding their folder location to the PATH env variable.