Skip to content

Commit 813af11

Browse files
mois-ilyaclaude
andcommitted
fix: resolve Buffer.alloc error in production build
Root cause: ES module imports are hoisted and execute before module body code. When vendor-ton was a separate chunk, it would load and execute before the Buffer polyfill in the main bundle, causing "Buffer.alloc is not a function". Solution: Remove vendor-ton from manualChunks to keep TON packages in the main bundle with the Buffer polyfill, ensuring correct execution order. Changes: - Remove vendor-ton manual chunk from vite.config.ts - Keep TON packages in main bundle alongside Buffer polyfill - Add explicit globalThis.Buffer setup in polyfills.ts for extra safety 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent fdd3fee commit 813af11

File tree

9 files changed

+1297
-1285
lines changed

9 files changed

+1297
-1285
lines changed

dist/404.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
<title>Demo Dapp with @tonconnect/ui-react</title>
99

1010
<script data-consolejs-channel="57e95ad4-4a89-7cf9-106a-51106eb4d73d" src="https://remotejs.com/agent/agent.js"></script>
11-
<script type="module" crossorigin src="/demo-dapp-with-wallet/relayers/assets/index-BjVcfrst.js"></script>
11+
<script type="module" crossorigin src="/demo-dapp-with-wallet/relayers/assets/index-DoeFefXp.js"></script>
1212
<link rel="modulepreload" crossorigin href="/demo-dapp-with-wallet/relayers/assets/vendor-react-Drc5ga--.js">
13-
<link rel="modulepreload" crossorigin href="/demo-dapp-with-wallet/relayers/assets/vendor-ton-DCgIeIEq.js">
13+
<link rel="modulepreload" crossorigin href="/demo-dapp-with-wallet/relayers/assets/vendor-crypto-DO72JQCC.js">
1414
<link rel="stylesheet" crossorigin href="/demo-dapp-with-wallet/relayers/assets/index-C6qF6Nog.css">
1515
</head>
1616
<body>

dist/assets/index-BjVcfrst.js

Lines changed: 0 additions & 29 deletions
This file was deleted.

dist/assets/index-DoeFefXp.js

Lines changed: 1256 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/assets/vendor-crypto-BxXtXh0r.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

dist/assets/vendor-crypto-DO72JQCC.js

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/assets/vendor-ton-DCgIeIEq.js

Lines changed: 0 additions & 1249 deletions
This file was deleted.

dist/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
<title>Demo Dapp with @tonconnect/ui-react</title>
99

1010
<script data-consolejs-channel="57e95ad4-4a89-7cf9-106a-51106eb4d73d" src="https://remotejs.com/agent/agent.js"></script>
11-
<script type="module" crossorigin src="/demo-dapp-with-wallet/relayers/assets/index-BjVcfrst.js"></script>
11+
<script type="module" crossorigin src="/demo-dapp-with-wallet/relayers/assets/index-DoeFefXp.js"></script>
1212
<link rel="modulepreload" crossorigin href="/demo-dapp-with-wallet/relayers/assets/vendor-react-Drc5ga--.js">
13-
<link rel="modulepreload" crossorigin href="/demo-dapp-with-wallet/relayers/assets/vendor-ton-DCgIeIEq.js">
13+
<link rel="modulepreload" crossorigin href="/demo-dapp-with-wallet/relayers/assets/vendor-crypto-DO72JQCC.js">
1414
<link rel="stylesheet" crossorigin href="/demo-dapp-with-wallet/relayers/assets/index-C6qF6Nog.css">
1515
</head>
1616
<body>

src/polyfills.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
11
import { Buffer } from 'buffer'
2+
3+
// Explicitly set global Buffer - vite-plugin-node-polyfills doesn't always do this in production
4+
if (typeof globalThis.Buffer === 'undefined') {
5+
(globalThis as any).Buffer = Buffer
6+
}
7+
8+
if (typeof window !== 'undefined' && typeof (window as any).Buffer === 'undefined') {
9+
(window as any).Buffer = Buffer
10+
}

vite.config.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ export default defineConfig(({ command }) => {
7171
output: {
7272
manualChunks: {
7373
'vendor-react': ['react', 'react-dom'],
74-
'vendor-ton': ['@ton/core', '@tonconnect/ui-react'],
75-
'vendor-crypto': ['crypto-browserify', 'tweetnacl', 'buffer', 'process']
74+
'vendor-crypto': ['crypto-browserify', 'tweetnacl']
7675
}
7776
}
7877
}

0 commit comments

Comments
 (0)