Add singleTab option for Worker in tab-less contexts like Capacitor apps
Capacitor apps use an instance of webview that don't have the navigator.locks API, thus the PGlite worker doesn't work in these contexts. It throws an error: "Cannot read properties of undefined (reading 'request')."
I propose updating the code to allow for singleTab worker usage. I would say that 90% of the benefit of the worker is the background thread ability and only 10% is multi-tab stuff. This allows us to still use the worker in apps built using Capacitor and other similar frameworks.
FYI, cloning down the repo (with submodules), pnpm install and then pnpm ts:build doesn't work. I'm on Linux.
pglite main ❯ pnpm ts:build
> @ ts:build /home/jacob/code/examples/pglite
> pnpm -r --filter "./packages/**" build
Scope: 9 of 13 workspace projects
packages/pg-protocol build$ tsup
[18 lines collapsed]
│ CJS dist/messages.cjs.map 11.69 KB
│ CJS ⚡️ Build success in 22ms
│ DTS Build start
│ DTS ⚡️ Build success in 555ms
│ DTS dist/index.d.cts 1.67 KB
│ DTS dist/messages.d.cts 762.00 B
│ DTS dist/messages-CaXcfh5Z.d.cts 12.65 KB
│ DTS dist/index.d.ts 1.67 KB
│ DTS dist/messages.d.ts 761.00 B
│ DTS dist/messages-CaXcfh5Z.d.ts 12.65 KB
└─ Done in 1s
packages/pglite build$ pnpm build:js
│ > @electric-sql/[email protected] build:js /home/jacob/code/examples/pglite/packages/pglite
│ > tsup && tsx scripts/bundle-wasm.ts
│ Cannot find release/pglite.js
│ CLI Building entry: src/index.ts, src/templating.ts, src/contrib/amcheck.ts, src/contrib/auto_explain.ts, src/contrib/bloom.ts, src/contrib/btree_gin.ts, src/contrib/btree_gist.ts, …
│ CLI Using tsconfig: tsconfig.json
│ CLI tsup v8.3.0
│ CLI Using tsup config: /home/jacob/code/examples/pglite/packages/pglite/tsup.config.ts
│ CLI Target: es2020
│ CLI Cleaning output folder
│ ESM Build start
│ CJS Build start
│ ✘ [ERROR] Could not resolve "../release/pglite"
│ src/postgresMod.ts:1:31:
│ 1 │ import PostgresModFactory from '../release/pglite'
│ ╵ ~~~~~~~~~~~~~~~~~~~
│ ✘ [ERROR] Could not resolve "../release/pglite"
│ src/postgresMod.ts:1:31:
│ 1 │ import PostgresModFactory from '../release/pglite'
│ ╵ ~~~~~~~~~~~~~~~~~~~
│ ESM Build failed
│ CJS Build failed
│ DTS Build start
│ src/postgresMod.ts(1,32): error TS2307: Cannot find module '../release/pglite' or its corresponding type declarations.
│ DTS Build error
│ ELIFECYCLE Command failed with exit code 1.
└─ Failed in 6.4s at /home/jacob/code/examples/pglite/packages/pglite
/home/jacob/code/examples/pglite/packages/pglite:
ERR_PNPM_RECURSIVE_RUN_FIRST_FAIL @electric-sql/[email protected] build: `pnpm build:js`
Exit status 1
ELIFECYCLE Command failed with exit code 1.
You need to do pnpm build:all. It's in the README.
On Thu, Oct 30, 2025, 11:23 Jacob Bowdoin @.***> wrote:
jacob-8 left a comment (electric-sql/pglite#832) https://github.com/electric-sql/pglite/pull/832#issuecomment-3467195458
FYI, cloning down the repo (with submodules), pnpm install and then pnpm ts:build doesn't work. I'm on Linux.
pglite main ❯ pnpm ts:build
@ ts:build /home/jacob/code/examples/pglite> pnpm -r --filter "./packages/**" build
Scope: 9 of 13 workspace projects packages/pg-protocol build$ tsup [18 lines collapsed] │ CJS dist/messages.cjs.map 11.69 KB │ CJS ⚡️ Build success in 22ms │ DTS Build start │ DTS ⚡️ Build success in 555ms │ DTS dist/index.d.cts 1.67 KB │ DTS dist/messages.d.cts 762.00 B │ DTS dist/messages-CaXcfh5Z.d.cts 12.65 KB │ DTS dist/index.d.ts 1.67 KB │ DTS dist/messages.d.ts 761.00 B │ DTS dist/messages-CaXcfh5Z.d.ts 12.65 KB └─ Done in 1s packages/pglite build$ pnpm build:js │ > @@.*** build:js /home/jacob/code/examples/pglite/packages/pglite │ > tsup && tsx scripts/bundle-wasm.ts │ Cannot find release/pglite.js │ CLI Building entry: src/index.ts, src/templating.ts, src/contrib/amcheck.ts, src/contrib/auto_explain.ts, src/contrib/bloom.ts, src/contrib/btree_gin.ts, src/contrib/btree_gist.ts, … │ CLI Using tsconfig: tsconfig.json │ CLI tsup v8.3.0 │ CLI Using tsup config: /home/jacob/code/examples/pglite/packages/pglite/tsup.config.ts │ CLI Target: es2020 │ CLI Cleaning output folder │ ESM Build start │ CJS Build start │ ✘ [ERROR] Could not resolve "../release/pglite" │ src/postgresMod.ts:1:31: │ 1 │ import PostgresModFactory from '../release/pglite' │ ╵ ~~~~~~~~~~~~~~~~~~~ │ ✘ [ERROR] Could not resolve "../release/pglite" │ src/postgresMod.ts:1:31: │ 1 │ import PostgresModFactory from '../release/pglite' │ ╵ ~~~~~~~~~~~~~~~~~~~ │ ESM Build failed │ CJS Build failed │ DTS Build start │ src/postgresMod.ts(1,32): error TS2307: Cannot find module '../release/pglite' or its corresponding type declarations. │ DTS Build error │ ELIFECYCLE Command failed with exit code 1. └─ Failed in 6.4s at /home/jacob/code/examples/pglite/packages/pglite /home/jacob/code/examples/pglite/packages/pglite: ERR_PNPM_RECURSIVE_RUN_FIRST_FAIL @@.*** build:
pnpm build:jsExit status 1 ELIFECYCLE Command failed with exit code 1.— Reply to this email directly, view it on GitHub https://github.com/electric-sql/pglite/pull/832#issuecomment-3467195458, or unsubscribe https://github.com/notifications/unsubscribe-auth/AI62W6QVQUVYT3WHVHQCHPD32HRJ3AVCNFSM6AAAAACKURUVXCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTINRXGE4TKNBVHA . You are receiving this because you are subscribed to this thread.Message ID: @.***>