Skip to content

feat(pglite): add unwasm export condition (Nitro / Nuxt support) - #1121

Closed
pi0x wants to merge 1 commit into
electric-sql:mainfrom
pi0x:feat/unwasm-export-condition
Closed

pi0x wants to merge 1 commit into
electric-sql:mainfrom
pi0x:feat/unwasm-export-condition

Conversation

@pi0x

@pi0x pi0x commented Oct 7, 2026

Copy link
Copy Markdown

Resolves #1120

This PR adds an unwasm export condition so PGlite works out of the box with Nitro.

Today, a Nitro build bundles PGlite but not its runtime files, so the first query fails:

ENOENT: no such file or directory, open '.output/server/_libs/pglite.data'

How it works

  • The unwasm condition resolves to a new dist/unwasm.js entry. It imports pglite.wasm and initdb.wasm as Wasm modules (?module), so the bundler includes them in its output.
  • pglite.data isn't a Wasm file, so at build time we also write it to pglite.data.wasm, a Wasm module with no code that holds the data in a custom section. The entry reads it back with WebAssembly.Module.customSections().
  • Other import paths aren't affected.

Testing

  • Repro from Feature request: Nitro 3 support (unwasm export condition) #1120 (Nitro 3, Node preset): fails on main, returns [{"one":1}] with this branch.
  • Nitro cloudflare-module preset: all three .wasm files are written to the output and loaded as native Wasm imports.
  • Rollup with unwasm and exportConditions: ['unwasm']: the bundle runs from a separate directory.
  • New tests/unwasm.test.ts checks the data round-trip and runs a query through the new entry.

🤖 Generated with AI assistant

Bundlers using unwasm (such as Nitro 3) resolve the `unwasm` condition to a
new entry that imports pglite.wasm and initdb.wasm via `?module`, and the FS
bundle as pglite.data.wasm (pglite.data wrapped in a Wasm custom section), so
they are included in the bundle instead of loaded from files at runtime.

Resolves electric-sql#1120
@pi0

pi0 commented Oct 7, 2026

Copy link
Copy Markdown

@tdrz kindly please LMK if you might be worried about size. we can support special handling for .wasm.gz for example in unwasm.

@tdrz

tdrz commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Two alternatives to try out:

  1. Manually package the data file

See our docs: https://pglite.dev/docs/bundler-support#esbuild

  1. Try this experimental build that embeds pglite.data into pglite.js

https://github.com/electric-sql/pglite/actions/runs/38247914340/artifacts/11747130932

Artifact created here: #1131

@tdrz

tdrz commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Closing as this is not the right solution for us. There are workarounds for custom bundlers that are documented here, we could add another section for Nitro/Nuxt.

@tdrz tdrz closed this Oct 13, 2026
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.

Feature request: Nitro 3 support (unwasm export condition)

3 participants