fix(desktop): stop using tsx to boot Electron main in dev

Electron 40 ships Node 24.15, where tsx's ESM load hook returns null and
crashes with ERR_INVALID_RETURN_PROPERTY_VALUE. Bundle main+preload via
esbuild for `npm run dev` and always load the JS preload from dist/.
This commit is contained in:
Brooklyn Nicholson 2026-07-08 22:40:51 -05:00
parent 513dba42e6
commit bf913abc2e
3 changed files with 19 additions and 15 deletions

View file

@ -25,9 +25,14 @@ const preloadEntry = resolve(root, 'electron/preload.ts')
const preloadOut = resolve(distDir, 'electron-preload.js')
const external = ['electron', 'node-pty', 'fs']
const define = {
'process.env.HERMES_DESKTOP_IS_PACKAGED': JSON.stringify(true)
}
// Production bundles bake packaged=true so unpackaged `electron .` still
// behaves like a packaged build. Dev bundles (`--dev`) leave the env alone
// so HERMES_DESKTOP_DEV_SERVER / source-tree resolution keep working.
const isDev = process.argv.includes('--dev')
const define = isDev
? {}
: { 'process.env.HERMES_DESKTOP_IS_PACKAGED': JSON.stringify(true) }
// Bundle main.ts → dist/electron-main.mjs
await build({
entryPoints: [mainEntry],
@ -37,15 +42,15 @@ await build({
target: 'node20',
outfile: mainOut,
external,
banner: {
banner: {
js: "import { createRequire } from 'module'; const require = createRequire(import.meta.url);",
},
define,
logLevel: 'info',
})
console.log(`bundled ${mainOut}`)
console.log(`bundled ${mainOut}${isDev ? ' (dev)' : ''}`)
// Bundle preload.ts → dist/electron-preload.cjs
// Bundle preload.ts → dist/electron-preload.js
await build({
entryPoints: [preloadEntry],
bundle: true,
@ -57,4 +62,4 @@ await build({
define,
logLevel: 'info',
})
console.log(`bundled ${preloadOut}`)
console.log(`bundled ${preloadOut}${isDev ? ' (dev)' : ''}`)