Skip to content

fix(personal-server): bundle JS deps with esbuild to fix MODULE_NOT_FOUND crash#103

Open
aculich wants to merge 1 commit intovana-com:mainfrom
aculich:fix/personal-server-module-resolution
Open

fix(personal-server): bundle JS deps with esbuild to fix MODULE_NOT_FOUND crash#103
aculich wants to merge 1 commit intovana-com:mainfrom
aculich:fix/personal-server-module-resolution

Conversation

@aculich
Copy link
Copy Markdown

@aculich aculich commented Apr 14, 2026

Summary

The personal server binary crashes on startup with:

Error: Cannot find module '@opendatalabs/personal-server-ts-core/config'

This makes the Personal Server unusable in the DataConnect v0.7.52 desktop app.

Root cause

The build script (personal-server/scripts/build.js) marks @opendatalabs/*, @hono/node-server, and hono as esbuild externals. This converts their ESM imports into CJS require() calls in the output bundle. These packages are then copied to dist/node_modules/ beside the binary, but two issues prevent runtime resolution:

  1. pkg path resolution: The _resolveFilename banner patch only redirects native addons (better-sqlite3, bindings, file-uri-to-path) to look beside process.execPath. The runtime JS externals aren't included, so pkg's virtual filesystem never finds them.
  2. ESM-only exports maps: The @opendatalabs packages only define "import" conditions in their exports maps — no "require" condition. Node 22.10.0 (the version embedded by pkg) cannot resolve ESM-only subpath exports via require() without the --experimental-require-module flag.

Fix

Let esbuild bundle all JS dependencies directly into the CJS output. Only native addons (better-sqlite3 and its dependencies) remain external, since they require real filesystem access. This eliminates runtime module resolution for JS packages entirely.

Results

  • Personal server starts successfully (tested locally)
  • Binary is ~44% smaller (66MB vs 118MB) since the dist/node_modules/ copies of JS packages are no longer needed
  • The pkg.assets config in package.json is cleaned up (those assets are now in the bundle)

Test plan

  • npm install in personal-server/
  • node scripts/build.js succeeds without errors
  • Built binary starts: PORT=9999 ./dist/personal-server outputs {"type":"ready","port":9999}
  • Verify in full DataConnect app build (Tauri)

Made with Cursor

…OUND crash

The personal server binary crashes on startup with:
  Error: Cannot find module '@opendatalabs/personal-server-ts-core/config'

Root cause: The build script marks @opendatalabs/*, @hono/node-server, and
hono as esbuild externals, converting their imports to require() calls in the
CJS bundle. These modules are copied to dist/node_modules/ beside the binary,
but two issues prevent runtime resolution:

1. pkg's virtual filesystem doesn't search beside process.execPath, and the
   _resolveFilename patch only redirects native addons (better-sqlite3 etc.)
2. The @opendatalabs packages only export ESM ("import" condition) — Node
   22.10.0 (embedded by pkg) can't resolve ESM-only subpath exports via
   require() without --experimental-require-module

Fix: Let esbuild bundle all JS dependencies directly (only native addons
remain external). This eliminates runtime module resolution for JS packages
entirely. The binary is also ~44% smaller (66MB vs 118MB) since duplicate
copies in dist/node_modules/ are no longer needed.

Made-with: Cursor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant