mirror of
https://github.com/dpup/meshstream.git
synced 2026-03-28 17:42:37 +01:00
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 <noreply@anthropic.com>
This commit is contained in:
@@ -15,7 +15,13 @@
|
||||
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script>window.__publicField = function(a, b, c) { a[b] = c; return c; };</script>
|
||||
<script>
|
||||
globalThis.__publicField = function(obj, key, value) {
|
||||
Object.defineProperty(obj, typeof key !== 'symbol' ? key + '' : key, {
|
||||
configurable: true, enumerable: true, writable: true, value: value
|
||||
});
|
||||
};
|
||||
</script>
|
||||
<script type="module" src="/src/main.tsx"></script>
|
||||
</body>
|
||||
|
||||
|
||||
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user