Skip to content

Commit dbdca1e

Browse files
authored
fix(builder): use terser minification to preserve wagmi TLA initialization (#320)
esbuild's minification reorders statements in a way that breaks Top-Level Await (TLA) initialization in wagmi connectors, causing runtime errors like "Cannot set properties of undefined (setting 'type')" in production builds. Changes: - Remove wagmi from manualChunks (code splitting exacerbates TLA issues) - Set build target to esnext to preserve native TLA syntax - Switch from esbuild to terser for minification (preserves TLA order) - Configure terser to not mangle top-level names This fixes EVM and Polkadot adapters failing to load networks in Docker/ production builds while working correctly in development mode.
1 parent 772e590 commit dbdca1e

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

apps/builder/vite.config.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,12 +374,13 @@ export default defineConfig(async (): Promise<UserConfig> => {
374374
// We use output.manualChunks to ensure wagmi deps are bundled separately
375375
output: {
376376
// Split chunks to reduce memory usage during build
377+
// NOTE: Do NOT add wagmi/@wagmi/core to manualChunks - they use Top-Level Await
378+
// which breaks when split into separate chunks due to minification reordering issues.
379+
// Let Rollup decide how to chunk wagmi for proper TLA initialization order.
377380
manualChunks: {
378381
vendor: ['react', 'react-dom'],
379382
ui: ['@radix-ui/react-accordion', '@radix-ui/react-checkbox', '@radix-ui/react-dialog'],
380383
web3: ['viem', '@tanstack/react-query'],
381-
// Wagmi dependencies - required by EVM adapter for dynamic imports
382-
wagmi: ['wagmi', '@wagmi/core'],
383384
},
384385
// Suppress sourcemap warnings for dependencies
385386
sourcemapIgnoreList: (relativeSourcePath: string) => {
@@ -393,8 +394,19 @@ export default defineConfig(async (): Promise<UserConfig> => {
393394
chunkSizeWarningLimit: 2000,
394395
// Reduce source map generation to save memory
395396
sourcemap: false,
397+
// Use esnext target to preserve Top-Level Await syntax natively
398+
// This is required because wagmi connectors use TLA which breaks with lower targets
399+
target: 'esnext',
396400
// Remove console and debugger in staging/production builds
397-
minify: 'esbuild',
401+
// NOTE: Use terser instead of esbuild to preserve TLA code order
402+
// esbuild's minification can reorder statements in a way that breaks TLA
403+
minify: 'terser',
404+
terserOptions: {
405+
// Keep variable names more intact to preserve initialization order
406+
mangle: {
407+
toplevel: false,
408+
},
409+
},
398410
},
399411
};
400412
return config;

0 commit comments

Comments
 (0)