ci: strip dead default-module-path branch from pg-wasm web build#199
Open
rubenhensen wants to merge 1 commit into
Open
ci: strip dead default-module-path branch from pg-wasm web build#199rubenhensen wants to merge 1 commit into
rubenhensen wants to merge 1 commit into
Conversation
wasm-bindgen's `--target web` output emits an unreachable
`module_or_path = new URL('index_bg.wasm', import.meta.url)` branch in
__wbg_init. Webpack 5 statically resolves it as an asset import at build
time even though it never fires for callers that pass module_or_path
explicitly (e.g. @e4a/pg-js), producing 'Can't resolve index_bg.wasm'
errors in downstream consumers.
wasm-pack does not expose wasm-bindgen's --omit-default-module-path flag,
so strip the branch from the generated index.js after the build. The
strip fails loudly if the pattern is gone so a future wasm-bindgen change
can't silently no-op it. The bundler target has no init function and is
unaffected.
Fixes #153
Contributor
|
Dobby hit a rate limit mid-task and had to pause. Resets 6/12/2026, 4:00:00 PM. I'll automatically resume where I left off — no work lost! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
@e4a/pg-wasmweb target generated bywasm-pack build --target webships an unreachable default-value branch in__wbg_init:Webpack 5 statically analyzes
new URL("...", import.meta.url)as an asset import and tries to resolveindex_bg.wasmat build time — even though the branch never fires for callers that always passmodule_or_pathexplicitly (e.g.@e4a/pg-js, which inlines the WASM as base64). Downstream consumers therefore hitModule not found: Can't resolve 'index_bg.wasm'.wasm-packdoes not expose wasm-bindgen's--omit-default-module-pathflag, so this PR adds a post-build step todelivery.yml'spublish-wasmjob that strips the branch from the generatedpg-wasm/pkg/web/index.js. The strip:ifcondition so a wasm-bindgen version change to e.g.typeof module_or_path === 'undefined'still matches.exit 1) if the pattern is gone, so a future wasm-bindgen change can't silently no-op the strip and ship the regression again.The bundler target is unaffected — it emits
import * as wasm from "./index_bg.wasm"with no__wbg_initfunction and nonew URL(...)branch — so no strip is needed there (this corrects fix-option 2 in the issue body).Verification
Built the web target locally with
wasm-pack 0.14.0and confirmed against the real generated output:pg-wasm/pkg/web/index.jsbefore stripping.nodescript from this PR removes the 3-line block, leaving zeroindex_bg.wasmreferences.__wbg_initflow is intact — control passes straight into thetypeof module_or_path === 'string' || ... instanceof Request || ... instanceof URLpath that fires when a caller passesmodule_or_pathexplicitly.node --checkpasses on the stripped file.Behavior change: a caller that invokes
init()with no argument now gets a runtime error at instantiate time instead of a webpack build-time error — exactly what--omit-default-module-pathproduces. All current consumers passmodule_or_path, so they are unaffected.Downstream
Once a new
@e4a/pg-wasmships with this fix,@e4a/pg-jsonly needs a dep bump + republish, and theparser: { url: false }webpack workaround in downstream consumers can be removed.Fixes #153