Skip to content

Conversation

simolus3
Copy link
Contributor

@simolus3 simolus3 commented Apr 7, 2025

The example in demos/example-electron-node has two problems that only occur when running the packaged builds (the generated app after running pnpm package):

  1. It opens databases in the current working directory. On macOS, that appears to be the read-only .app file of the app itself by default, where we can't open databases. This changes the example to use a directory in app.getPath('userData') instead.
  2. All assets get put into an archive (app.asar) by default. Electron patches some Node APIs to be aware of this (so e.g. calling process.dlopen would automatically extract the relevant library), but SQLite obviously can't be aware of that when we're loading the extension. So:
  • I've changed the copy step responsible for copying the native PowerSync loadable core extension into a powersync/ directory.
  • Then, asar is configured to create an uncompressed copy of the extension.
  • Finally, in worker.ts, we check whether __dirname points to the archive, and, if so, use the extracted directory instead.

@simolus3 simolus3 merged commit 81045a5 into main Apr 17, 2025
6 checks passed
@simolus3 simolus3 deleted the fix-packaged-node-electron-demo branch April 17, 2025 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants