Skip to content

Commit f7fbfb8

Browse files
steveseguinclaude
andcommitted
Fix native module loading in packaged app
- Add asarUnpack config to extract .node and .dll files from asar - Update module loading to try multiple paths including app.asar.unpacked - Log which path the module loads from for debugging Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 25114c2 commit f7fbfb8

File tree

3 files changed

+53
-16
lines changed

3 files changed

+53
-16
lines changed

native-modules/electron-asio/index.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,32 @@ let nativeModule = null;
1313
let isInitialized = false;
1414

1515
/**
16-
* Load the native ASIO module
16+
* Load the native ASIO module - handles both development and packaged paths
1717
*/
1818
function loadNativeModule() {
1919
if (nativeModule) return nativeModule;
2020

21-
try {
22-
// Try loading from build/Release (development)
23-
const modulePath = path.join(__dirname, 'build', 'Release', 'electron_asio.node');
24-
nativeModule = require(modulePath);
25-
return nativeModule;
26-
} catch (err) {
27-
console.warn('[electron-asio] Failed to load native module:', err.message);
28-
return null;
21+
const moduleName = 'electron_asio.node';
22+
const possiblePaths = [
23+
// Development: relative to index.js
24+
path.join(__dirname, 'build', 'Release', moduleName),
25+
path.join(__dirname, 'build', 'Debug', moduleName),
26+
// Packaged app: asar unpacked path
27+
path.join(__dirname.replace('app.asar', 'app.asar.unpacked'), 'build', 'Release', moduleName),
28+
];
29+
30+
for (const modulePath of possiblePaths) {
31+
try {
32+
nativeModule = require(modulePath);
33+
console.log('[electron-asio] Loaded native module from:', modulePath);
34+
return nativeModule;
35+
} catch (err) {
36+
// Continue to next path
37+
}
2938
}
39+
40+
console.warn('[electron-asio] Native module not found in any expected location');
41+
return null;
3042
}
3143

3244
/**

native-modules/electron-asio/lib/index.js

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,37 @@
77
const path = require('path');
88
const EventEmitter = require('events');
99

10-
// Load native addon
10+
// Load native addon - handles both development and packaged (asar unpacked) paths
1111
let native = null;
12+
function loadNativeModule() {
13+
const moduleName = 'electron_asio.node';
14+
const possiblePaths = [
15+
// Development: relative to lib/index.js
16+
path.join(__dirname, '..', 'build', 'Release', moduleName),
17+
path.join(__dirname, '..', 'build', 'Debug', moduleName),
18+
// Packaged app: asar unpacked path
19+
path.join(__dirname.replace('app.asar', 'app.asar.unpacked'), '..', 'build', 'Release', moduleName),
20+
];
21+
22+
for (const modulePath of possiblePaths) {
23+
try {
24+
const mod = require(modulePath);
25+
console.log('[electron-asio] Loaded native module from:', modulePath);
26+
return mod;
27+
} catch (e) {
28+
// Continue to next path
29+
}
30+
}
31+
return null;
32+
}
33+
1234
try {
13-
native = require('../build/Release/electron_asio.node');
14-
} catch (e) {
15-
try {
16-
native = require('../build/Debug/electron_asio.node');
17-
} catch (e2) {
18-
console.warn('[electron-asio] Native module not available:', e.message);
35+
native = loadNativeModule();
36+
if (!native) {
37+
console.warn('[electron-asio] Native module not found in any expected location');
1938
}
39+
} catch (e) {
40+
console.warn('[electron-asio] Failed to load native module:', e.message);
2041
}
2142

2243
/**

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
"productName": "elecap",
3636
"electronVersion": "39.2.13-qp20",
3737
"npmRebuild": false,
38+
"asarUnpack": [
39+
"native-modules/**/*.node",
40+
"native-modules/**/*.dll"
41+
],
3842
"electronDownload": {
3943
"mirror": "https://github.com/steveseguin/electron/releases/download/",
4044
"customDir": "v39.2.13-qp20"

0 commit comments

Comments
 (0)