I use sqlite in my application. When running the application from source (electron ./) I have no trouble reading the file:
const fileBuffer = fs.readFileSync('data/db.sqlite');
Which I then pass to sql.js.
However after packaging using electron-packager, this line of code throws the error:
Uncaught Error: ENOENT: no such file or directory, open 'data/db.sqlite'
I thought it might have to do with the relative location of the file. As a (very crude) test I copied the db.sqlite file to every directory from the root of the packaged app to the sql.js node_module. This did not help.
I can’t seem to figure out the behavior of the ‘fs’ module in this context: what is the starting path when calling readFileSync(). I expected it to be the directory of the file containing the code. Which in my case would be in ‘resources/app/dist/build.js’ relative to the packaged electron executable.
My sqlite db is at ‘resources/app/data/sqlite.db’. So I tried ‘…/data/sqlite.js’, which didn’t work. Also tried ‘resources/app/data/sqlite.db’ thinking the start might be the location of the executable.
I was hoping someone could point me in the right direction here.
Fixed by using process