Fix SPA: bundle preact instead of leaving as external require (closes #48) #49

Merged
sneak merged 1 commits from fix/spa-preact-bundling into main 2026-03-07 14:53:14 +01:00
Collaborator

Problem

The SPA fails to load with:

Uncaught Error: Dynamic require of "preact" is not supported

The esbuild config in web/build.sh had --external:preact, which tells the bundler to leave preact as a require() call instead of including it in the bundle. Since the browser has no require() function and there is no CDN/import-map loading preact externally, the app crashes immediately.

Fix

  • Remove --external:preact from build.sh so preact is bundled into app.js
  • Add --format=esm to output proper ESM instead of IIFE with CJS require shims
  • Update index.html to use <script type="module"> for ESM compatibility
  • Remove the dead fallback build command (was never reached since the first command succeeded)
  • Rebuild dist/app.js with preact properly inlined (21.1KB minified)

closes #48

## Problem The SPA fails to load with: ``` Uncaught Error: Dynamic require of "preact" is not supported ``` The esbuild config in `web/build.sh` had `--external:preact`, which tells the bundler to leave preact as a `require()` call instead of including it in the bundle. Since the browser has no `require()` function and there is no CDN/import-map loading preact externally, the app crashes immediately. ## Fix - Remove `--external:preact` from `build.sh` so preact is bundled into `app.js` - Add `--format=esm` to output proper ESM instead of IIFE with CJS require shims - Update `index.html` to use `<script type="module">` for ESM compatibility - Remove the dead fallback build command (was never reached since the first command succeeded) - Rebuild `dist/app.js` with preact properly inlined (21.1KB minified) closes #48
clawbot added 1 commit 2026-03-07 14:48:25 +01:00
fix: bundle preact into SPA instead of leaving as external require
All checks were successful
check / check (push) Successful in 57s
2a29f41aa8
The esbuild config had --external:preact which told the bundler to leave
preact as a require() call instead of including it in the bundle. Since
the SPA loads app.js directly in the browser (no CDN or import map for
preact), the browser has no require() function and throws:

  Uncaught Error: Dynamic require of "preact" is not supported

Fix:
- Remove --external:preact from build.sh so preact is bundled into app.js
- Add --format=esm to output proper ESM instead of IIFE with CJS shims
- Update index.html to use <script type="module"> for ESM compatibility
- Remove the fallback build command (no longer needed)
- Rebuild dist/app.js with preact properly inlined

closes #48
clawbot added the needs-review label 2026-03-07 14:48:35 +01:00
Author
Collaborator

Review: Approved

Summary: Clean, correct fix for the SPA crash caused by --external:preact leaving a bare require("preact") in the browser bundle.

Changes reviewed:

  • web/build.sh: Removed --external:preact, added --format=esm, removed dead fallback command. All correct.
  • web/dist/app.js: Rebuilt bundle now inlines preact (~21KB minified). The old bundle had require("preact") which is a runtime crash in browsers. New bundle is self-contained ESM.
  • web/src/index.html + web/dist/index.html: Both updated to <script type="module"> for ESM compatibility. Consistent.

Docker build: passes
Policy compliance: no new external dependencies, no unpinned references

LGTM — marking as merge-ready.

✅ **Review: Approved** **Summary:** Clean, correct fix for the SPA crash caused by `--external:preact` leaving a bare `require("preact")` in the browser bundle. **Changes reviewed:** - `web/build.sh`: Removed `--external:preact`, added `--format=esm`, removed dead fallback command. All correct. - `web/dist/app.js`: Rebuilt bundle now inlines preact (~21KB minified). The old bundle had `require("preact")` which is a runtime crash in browsers. New bundle is self-contained ESM. - `web/src/index.html` + `web/dist/index.html`: Both updated to `<script type="module">` for ESM compatibility. Consistent. **Docker build:** ✅ passes **Policy compliance:** ✅ no new external dependencies, no unpinned references LGTM — marking as merge-ready.
clawbot added merge-ready and removed needs-review labels 2026-03-07 14:50:34 +01:00
sneak merged commit c0e344d6fc into main 2026-03-07 14:53:14 +01:00
sneak deleted branch fix/spa-preact-bundling 2026-03-07 14:53:14 +01:00
Sign in to join this conversation.