I’ve started the Realm-provided realm-electron-advanced-quickstart found here.
Everything works fine when running in dev, but when I package this with electron-builder, the app does not work. I moved createWindow() to the top of the app.whenReady() function so I could see the debugger, and it showed the following message:
Failed to open realm: Error: illegal operation on a directory
at run (renderer.js:26)
Line 26 is
const realm = new Realm(config);
I suspect this is some sort of path/permissions issue with the .realm file.
In main.js , I changed the path in the realm config to
But I could not do so on renderer.js .
I’m running Node v14.15.4.
I would appreciate any ideas or examples of how this has been implemented before. I could not find any official guidance on the support docs about how .realm files should be handled in packaged apps. It would be great if the readme on realm-electron-advanced-quickstart explained best practices for packaging the app.
More specifically you might be interested in the code that changes the current working directory of the renderer process to be a sub-directory of the userData directory: realm-studio/process-directories.ts at channel/major-13 · realm/realm-studio · GitHub … Realm Studio does this, since opening a synced Realm will create a directory named mongodb-realm (or realm-object-server pre v10 of the SDK) relative to the current working directory, containing metadata about the currently authenticated users.
Thanks a bunch for that resource. I changed the working directory to userData, and that solved the problem.
I noticed that in the Realm Studio example, the main process and renderer processes each use a separate directory, and thus use separate .realm files. Does this approach have any advantages over having the main and renderer share a working directory and .realm file? It seems like it would be inefficient to have the same data stored in two places.