Skip to content

Commit 4eaa5bb

Browse files
alichherawallaUserclaude
authored
fix(build): bundle @scure/bip39 into main (ESM-only, avoid ERR_REQUIRE_ESM) (#29)
@scure/bip39 + @noble/hashes are ESM-only ("type":"module"). electron-vite externalizes deps for the main process by default, so a CJS main require()-ing them throws ERR_REQUIRE_ESM at runtime — when the vault recovery-phrase code loads, not at build (tsc/CI verify never catches it). Exclude both from externalizeDepsPlugin so Rollup bundles them into the main chunk instead. Verified against a packaged build: out/main has no external require of @scure/@noble, generateMnemonic + the full BIP39 wordlist are inlined in the recovery chunk, and the 11 recovery unit tests pass. Co-authored-by: User <user@Users-MacBook-Pro-174.local> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 2dcdde1 commit 4eaa5bb

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

electron.vite.config.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { resolve } from 'path'
22
import { existsSync } from 'fs'
3-
import { defineConfig } from 'electron-vite'
3+
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
44
import react from '@vitejs/plugin-react'
55
import tailwindcss from '@tailwindcss/vite'
66

@@ -24,6 +24,13 @@ const proDefine = { __OFFGRID_PRO__: JSON.stringify(proExists) }
2424
export default defineConfig({
2525
main: {
2626
define: proDefine,
27+
// Deps are externalized by default (resolved from node_modules at runtime).
28+
// @scure/bip39 + @noble/hashes are ESM-only ("type":"module"); a CJS main
29+
// process require()-ing them throws ERR_REQUIRE_ESM at runtime. Exclude them
30+
// from externalization so Rollup BUNDLES them into the main chunk (transpiled
31+
// to the output format), sidestepping the ESM/CJS boundary. Used by the pro
32+
// vault recovery-phrase feature (pro/main/vault/vault-recovery.ts).
33+
plugins: [externalizeDepsPlugin({ exclude: ['@scure/bip39', '@noble/hashes'] })],
2734
resolve: {
2835
alias: {
2936
'@offgrid/core': resolve('src'),

0 commit comments

Comments
 (0)