I'm trying to use child_process.fork()
in my Electron application.
I'm using electron-builder
. Everything seems to be working when running the application with the unpacked version. Once, the application is installed via NSIS the fork is not working at all. I checked all paths and they are fine.
I'm running the program on Windows as administrator.
The logs when running the installed app:
Script to be ran:
C:\Program Files\electron-app\resources\data\src\index.js
Executable:
Executable: C:\Program Files\electron-app\app.exe
The logs when running the unpacked app:
Script to be ran:
D:\Workspace\electron-app\dist\win-unpacked\resources\data\src\index.js
Executable:
D:\Workspace\electron-app\dist\win-unpacked\app.exe
The way I fork the child process in the main process is:
ipcMain.on(START, (event, config) => {
if (isDev) {
child = fork('./src/index.js', [config]);
} else {
const dataPath = path.join(process.resourcesPath, 'data');
const childPath = path.join(dataPath, 'src');
log.info('Trying to start...', childPath);
log.info('Config: ', config);
log.info('Executable: ', process.execPath);
child = fork(`${childPath}/src/index.js`, [config]);
}
});
And the source for the child process is copied into the extraResources folder on build:
"extraResources": [
{
"from": "./src/",
"to": "data/src",
"filter": [
"**/*"
]
}
]