Electron Forge App: Issues with Executable Fiel Location in Release Build
I have an Electron Forge application designed to launch a Django server (on Windows). The Django server is compiled into an executable file using PyInstaller. The Electron Forge application invokes this executable file via the spawn command.
When I build the Electron Forge application using npm run make
, the application functions as expected. However, when using npm run release
(which generates a setup file), the executable file cannot be located. Additionally, it does not exist in the resource folder.
I get the error when starting the server:
Error: spawn C:\Users\****\AppData\Local\Programs\****\resources\django-server\server.exe ENOENT
My forge.config.ts file:
Const config: ForgeConfig = {
packagerConfig: {
asar:true,
icon "./src/assets/Logo/icon"
extraResources: ['./django-server/server.exe']
}
makers: [
new MakerSquirrel({noMsi: false}),
new MakerZIP({})
], ....
The server.exe file is started inside the index.ts file by using spawn:
exePath = path.join(process.resourcesPath, 'django-server', 'server.exe');
const child = spawn(exePath, []);
Why is the server.exe file not being copied to the resource folder when running npm run release
?
The issue was that the configuration of electron-forge and electron-builder was not correct. Electron-forge was used for npm run make
and it works well. The release part was build with the electron-builder and this configuration was wrong.
To embed the icons and the server.exe file into the electron app, these resources had to be specified in the package.json
file.
"build": {
"win": {
"icon": icon "src/assets/Logo/icon",
"extraResources": ["django-server/server.exe"]
}
}