Skip to content

build: fix buffer import shims for stellar-sdk 16, release 0.5.29 - #45

Merged
AquiGorka merged 1 commit into
mainfrom
fix/sdk16-buffer-shims
Jul 29, 2026
Merged

build: fix buffer import shims for stellar-sdk 16, release 0.5.29#45
AquiGorka merged 1 commit into
mainfrom
fix/sdk16-buffer-shims

Conversation

@AquiGorka

Copy link
Copy Markdown
Contributor

Root cause

stellar-sdk 16's ESM build emits two buffer import forms that the post-build patches in src/build.ts did not handle, so the browser bundle failed to evaluate and the app rendered nothing (the Invite Gate failure on this repo):

  1. Bare side-effect imports (import "buffer";) in lib/esm/base/generated and lib/esm/base/numbers (23 sites). Browsers cannot resolve a bare specifier: TypeError: Failed to resolve module specifier "buffer" kills the whole module graph. Fix: stripped, same as the existing named-import handling; Buffer is provided globally by the injected shim.

  2. Named imports (import { Buffer as BufferN } from "buffer") at hoisted bundle positions that execute before the injected shim's lazy init runs. Binding them to globalThis.__buffer_polyfill (previous approach) throws __buffer_polyfill is undefined. Fix: bind through the bundled npm buffer package's CJS factory (require_buffer().Buffer), which is defined near the top of the bundle, idempotent, and detected via its path-string key so it survives production minification.

Verification

  • local-dev ./test.sh invite-gate: 6/6 green (was 4/6 with both moonlight-pay tests failing)
  • Login page renders the Connect Wallet button with zero page/console errors (headless chromium + manual browser check)

Notes

  • CI note: the invite-gate compose could not even build a bundle until local-dev#137 (Deno image pin vs the 24h minimum-dependency-age policy on deno:latest). That PR also uploads Playwright artifacts so the next browser-side failure is a log read instead of a hunt.
  • deno.lock untouched; version bumped to 0.5.29 per release convention.

stellar-sdk 16 ESM emits two buffer import forms the post-build patches
did not handle, so the invite gate browser bundle failed to evaluate and
the app rendered nothing:

1. Bare side-effect imports (import "buffer";) in base/generated and
   base/numbers. Browsers cannot resolve the bare specifier and the whole
   module graph fails with: Failed to resolve module specifier "buffer".
   Now stripped; Buffer is provided by the injected shim.

2. Named imports (import { Buffer as BufferN } from "buffer") at hoisted
   positions that execute before the injected shim initializes, so binding
   them to globalThis.__buffer_polyfill produced
   "__buffer_polyfill is undefined". Now bound through the bundled npm
   buffer package's CJS factory, which is defined near the top of the
   bundle, idempotent, and whose name survives minification via its
   un-renamable path-string key.

Verified: local-dev ./test.sh invite-gate green 6/6, and the login page
renders the connect wallet button with no console errors.
@AquiGorka
AquiGorka merged commit f2d0905 into main Jul 29, 2026
6 of 8 checks passed
@AquiGorka
AquiGorka deleted the fix/sdk16-buffer-shims branch July 29, 2026 12:44
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.

1 participant