Repository navigation
Commit 85d4d2d
committed
Fix Electron main process crashing on startup (node-llama-cpp ESM/CJS)
node-llama-cpp is ESM with top-level await; this app compiles to
CommonJS, so a static import compiled straight to require(), which
throws ERR_REQUIRE_ASYNC_MODULE and took down the whole main process on
launch - nothing in the app was reachable, including Settings.
A plain dynamic import() didn't fix it either: TypeScript's CommonJS
output rewrites import(x) into Promise.resolve().then(() => require(x)),
which is the exact same broken require() just wrapped in a promise.
Verified this by inspecting the compiled dist/llamacpp-manager.js output
directly rather than assuming dynamic import would be enough.
Fixed by building the import() call via `new Function(...)` so
TypeScript can't see (and rewrite) it - this forces Node's real ESM
dynamic import at runtime instead of the broken require(). Verified by
actually launching the Electron dev app (previously crashed instantly;
now starts and runs normally).1 parent 3eb851f commit 85d4d2d
1 file changed
Lines changed: 26 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
5 | 15 | | |
6 | 16 | | |
7 | 17 | | |
8 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
9 | 30 | | |
10 | 31 | | |
11 | 32 | | |
| |||
25 | 46 | | |
26 | 47 | | |
27 | 48 | | |
| 49 | + | |
28 | 50 | | |
29 | 51 | | |
30 | 52 | | |
31 | 53 | | |
32 | 54 | | |
33 | 55 | | |
34 | 56 | | |
| 57 | + | |
35 | 58 | | |
36 | 59 | | |
37 | 60 | | |
| |||
122 | 145 | | |
123 | 146 | | |
124 | 147 | | |
| 148 | + | |
125 | 149 | | |
126 | 150 | | |
127 | 151 | | |
| |||
0 commit comments