Skip to content

fix(pg-wasm): omit default-module-path in web wasm-bindgen glue (#153)#222

Merged
rubenhensen merged 1 commit into
mainfrom
fix/153-omit-default-module-path
Jul 10, 2026
Merged

fix(pg-wasm): omit default-module-path in web wasm-bindgen glue (#153)#222
rubenhensen merged 1 commit into
mainfrom
fix/153-omit-default-module-path

Conversation

@dobby-coder

@dobby-coder dobby-coder Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Summary

wasm-pack build --target web (shipped as @e4a/pg-wasm) generated an unreachable default-module-path branch in __wbg_init:

if (module_or_path === undefined) {
    module_or_path = new URL('index_bg.wasm', import.meta.url);
}

Webpack 5 statically analyzes new URL("...", import.meta.url) as an asset import and tries to resolve index_bg.wasm at build time — even though the branch never fires for callers that always pass module_or_path explicitly (e.g. @e4a/pg-js, which inlines the WASM as base64). Downstream consumers therefore hit Module not found: Can't resolve 'index_bg.wasm'.

Fix

Enable wasm-bindgen's --omit-default-module-path (the issue's preferred option 1) via wasm-pack's release-profile metadata in pg-wasm/Cargo.toml:

[package.metadata.wasm-pack.profile.release.wasm-bindgen]
omit-default-module-path = true

wasm-pack does support this flag through manifest metadata (confirmed on wasm-pack 0.15.0, the version CI installs), so the branch is never generated in the first place. This keeps the fix in the crate manifest — no workflow change and no fragile post-build regex strip against generated output.

This supersedes #199, which stripped the branch with a post-build node regex in delivery.yml. That approach works but (a) is a workflow-only change and (b) matches generated output by pattern. This PR uses the actual --omit-default-module-path flag instead, so it's robust to wasm-bindgen formatting changes and touches only Cargo.toml.

Verification (locally, wasm-pack 0.15.0)

  • Before: pg-wasm/pkg/web/index.js contains the new URL('index_bg.wasm', import.meta.url) branch (lines 1235–1237).
  • After: rebuilding --target web with the metadata → zero index_bg.wasm / new URL(...) references; __wbg_init retains the explicit-module_or_path path (object-unwrap + string | Request | URLfetch). Callers passing module_or_path are unaffected; a caller passing nothing now errors at instantiate time, exactly as --omit-default-module-path intends.
  • Bundler target unaffected: it emits import * as wasm from "./index_bg.wasm" (a legitimate static module import, not the import.meta.url asset pattern) with no __wbg_init — so no dead branch exists there and none is introduced. This corrects fix-option 2 in the issue body.
  • cargo metadata parses the manifest; cargo fmt --all -- --check clean (no Rust changed). package.metadata is ignored by cargo, so the Rust test suite is unaffected; the wasm-pack build --release runs for both targets (the exact CI code path) succeed.

Downstream

Once a new @e4a/pg-wasm ships with this, @e4a/pg-js only needs a dep bump + republish, and the parser: { url: false } webpack workaround in downstream consumers can be removed.

Fixes #153

🤖 Generated with Claude Code

wasm-pack's `--target web` output emitted an unreachable default-module-path
branch (`module_or_path = new URL('index_bg.wasm', import.meta.url)`) in
__wbg_init. Webpack 5 statically resolves `new URL(..., import.meta.url)` as an
asset import at build time even though the branch never fires for callers that
always pass `module_or_path` (e.g. @e4a/pg-js, which inlines the wasm as
base64), so downstream consumers hit `Module not found: Can't resolve
'index_bg.wasm'`.

Enable wasm-bindgen's --omit-default-module-path via wasm-pack's release-profile
metadata so the branch is never generated. This is the issue's preferred fix and
lives in the crate manifest, so no fragile post-build regex strip is needed. The
bundler target is unaffected (static `import * as wasm from './index_bg.wasm'`,
no init function). Callers that pass module_or_path explicitly are unchanged; a
caller passing nothing now errors at instantiate time, exactly as the flag
intends.

Fixes #153

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@dobby-coder dobby-coder Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rules Dobby 2 gatekeeper review — cycle 1. 0 confirmed findings; clean.

Per-rule Haiku sweep merged with Review Dobby 2's findings (0). The diff is textbook-correct against our own memory (postguard-wasm-pack-omit-default-module-path): wasm-pack 0.15.0 honors omit-default-module-path via [package.metadata.wasm-pack.profile.release.wasm-bindgen], the bundler target correctly needs no change, and cargo ignores package.metadata so the build is the check — verified: --target web now emits 0 index_bg.wasm / new URL(import.meta.url) refs while the explicit module_or_path fetch path is retained.

Two Haiku-raised flags reviewed and dismissed: (1) tests-required — the metadata is cargo-ignored, so there is no testable unit; build-output verification is the correct and completed check; (2) justification-comment — the comment documents a non-obvious webpack static-resolution interaction a maintainer needs to keep the flag, not a rationale-narration of a self-evident deletion.

Submitted as COMMENT (APPROVE is rejected on a self-authored PR); routing on findings = clean → ready-for-review.

@dobby-coder
dobby-coder Bot marked this pull request as ready for review July 3, 2026 17:20
@rubenhensen
rubenhensen merged commit 3d13ac1 into main Jul 10, 2026
21 checks passed
@rubenhensen
rubenhensen deleted the fix/153-omit-default-module-path branch July 10, 2026 08:40
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.

pg-wasm: web target ships dead new URL("index_bg.wasm", import.meta.url) that breaks bundler consumers

1 participant