From 38798de9ca7ea7e0fbac4b1ec277a3fec7140473 Mon Sep 17 00:00:00 2001 From: Daniel Pupius Date: Sun, 15 Mar 2026 23:57:28 +0000 Subject: [PATCH] Fix __publicField with vite define + globalThis polyfill The previous index.html polyfill set window.__publicField but Vite's dep optimizer pre-bundles in Node.js where that global is never set, so the error persisted. Two-part fix: - vite.config.ts define: rewrite bare __publicField identifiers to globalThis.__publicField (a valid entity name esbuild accepts) - index.html: set globalThis.__publicField using the exact Object.defineProperty signature esbuild expects, before modules run Co-Authored-By: Claude Sonnet 4.6 --- web/index.html | 8 +++++++- web/vite.config.ts | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/web/index.html b/web/index.html index 934e76c..100d9fb 100644 --- a/web/index.html +++ b/web/index.html @@ -15,7 +15,13 @@
- + diff --git a/web/vite.config.ts b/web/vite.config.ts index fac8819..0e21f22 100644 --- a/web/vite.config.ts +++ b/web/vite.config.ts @@ -5,6 +5,12 @@ import { resolve } from 'path'; // https://vitejs.dev/config/ export default defineConfig({ + define: { + // Some pre-compiled npm packages use __publicField (a TypeScript/esbuild helper) + // without bundling it. Rewrite bare references to a globalThis property that + // we polyfill in index.html before any module code runs. + '__publicField': 'globalThis.__publicField', + }, plugins: [ react(), TanStackRouterVite(),