I am building my first electron app that has application content (a JSON file).
My problem is that I cannot access the application content after packaging with electron-build.
I added the JSON file (mvdb.json) in question to the external resources and resolve the path in the main process.
package.json
"build": {
"appId": "com.example.app",
"extraResources": ["mvdb.json"],
"mac": {
"category": "your.app.category.type"
},
"win": { "target": ["portable", "NSIS"]
},
"directories": {
"output": "release"
}
},
main.js
const fs = require('fs');
const isDev = process.env.NODE_ENV !== 'production'
// Load MOVIE Database
const MOVIE_DB_PATH = isDev ? path.join(__dirname, 'mvdb.json') : path.join(process.resourcesPath, 'mvdb.json');
...
fs.readFileSync(MOVIE_DB_PATH)
The macOS package build has the mvdb.json file in the Contents/Ressources folder, but when launched I get the error message
Uncaught Exception:
Error: ENOENT, mvdb.json not found in /Users/me/Documents/projects/screenwriters-delight/electron/release/mac/screenwriters-delight.app/Contents/Resources/app.asar
at createError (electron/js2c/asar.js:111:17)
at Object.fs.readFileSync (electron/js2c/asar.js:548:24)
at loadDB ...
Any suggestions?