diff --git a/.changeset/electron-main-process-in-node.md b/.changeset/electron-main-process-in-node.md new file mode 100644 index 000000000..1bd2b4b55 --- /dev/null +++ b/.changeset/electron-main-process-in-node.md @@ -0,0 +1,5 @@ +--- +'@electric-sql/pglite': patch +--- + +Detect the Node environment via `process.type` instead of `process.versions.electron`. The previous Electron guard (#951) also treated the Electron main and utility processes as non-Node, which broke PGlite's filesystem code path there. `process.type` only excludes Electron's web contexts (renderer, web worker, service worker), so PGlite keeps using the Node.js path in the Electron main and utility processes. Follow-up to #951 / #813. diff --git a/packages/pglite-utils/src/utils.ts b/packages/pglite-utils/src/utils.ts index 306c386bb..30c9ad7cd 100644 --- a/packages/pglite-utils/src/utils.ts +++ b/packages/pglite-utils/src/utils.ts @@ -1,8 +1,16 @@ +// Electron exposes a Node-like `process` in its renderer/worker/service-worker +// contexts, which must use the browser fs path. Its main and utility processes +// are real Node environments (#813). +function isElectronWebContext(): boolean { + const type = (process as { type?: string }).type + return type === 'renderer' || type === 'worker' || type === 'service-worker' +} + export const IN_NODE = typeof process === 'object' && typeof process.versions === 'object' && typeof process.versions.node === 'string' && - !process.versions.electron + !isElectronWebContext() export const WASM_PREFIX = '/pglite'