Unable to load native addon after electron-builder
See original GitHub issue- Version: 19.35.1
- Target: Windows 10 x64
Hi all, I’m trying to package an Electron application with a custom native addon (i.e. written by me), and have been unsuccessful so far. The app builds, but when I run it, it’s unable to load the native module, and exits.
Running the app locally, with electron .
works just fine, which leads me to believe that the native module has not been packaged with the executable.
My package.json looks like this:
{
"build": {
"appId": "App name",
"productName": "App company",
"copyright": "Copyright © 2017 App Inc.",
"nsis": {},
"win": {
"target": "nsis"
},
"mac": {
"target": "dmg"
}
},
"scripts": {
"pack": "electron-builder --dir",
"dist": "electron-builder -w --x64 --ia32"
},
"postinstall": "electron-builder install-app-deps",
"devDependencies": {
"electron-builder": "^19.6.3"
}
}
And the app directory structure like this:
application-root-dir
-app
-addon
-build
-Release
-addon.node
-addon.sln
-node_modules
-main.js
-package.json
-build
-node_modules
-package.json
Addon source code and MSVC project files, as well as *.node files are all in application-root-dir/app/addon/*
When I run npm run dist
, I get the following output:
> electron-builder -w --x64 --ia32
electron-builder 19.35.1
No native production dependencies
Packaging for win32 x64 using electron 1.6.14 to dist\win-unpacked
No native production dependencies
Packaging for win32 ia32 using electron 1.6.14 to dist\win-ia32-unpacked
Building nsis installer (x64 and ia32)
So, everything seemingly builds just fine, and the app installs successfully, but when I try to run, it’s unable to load the native module (from main.js
), and just exits. Below is the manner in which I load/require the module:
var addon
try {
addon= worker (
path.join(__dirname, './addon/build/Release/addon'),
{name: 'addon'}
);
}
catch(err) {
try {
addon= worker (
path.join(__dirname, './addon/build/Debug/addon'),
{name: 'addon'}
);
}
catch(err) {
log.error('Unable to load addon, exiting app...')
app.exit()
}
}
Any help would be appreciated.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:9
Top GitHub Comments
Settings
"nodeGypRebuild":"true"
in root package.json solved above issue.@Cprofessor3 unfortunately not; in the end, we moved away from electron and used CEF instead.