From 1b93b7c37673137b1799d2f96091a0a159f9e3a8 Mon Sep 17 00:00:00 2001 From: RECTOR Date: Sat, 6 Jun 2026 05:39:08 +0700 Subject: [PATCH] fix(agent): use tsup watcher for dev mode instead of tsx Fixes #253. `tsx watch src/index.ts` has crashed at boot since Phase D: @bonfida/spl-name-service@3.0.21 ships a borsh ESM bundle that tsx's ESM loader cannot instantiate (plain Node handles it fine). Switch the agent dev script to `tsup --watch src --onSuccess 'node dist/index.js'`, matching the root pattern. tsup transpiles only the agent's own source and runs the output with plain node, sidestepping tsx's loader. skipNodeModulesBundle is required: bundling the transitive CJS chain (bs58 -> safe-buffer -> require("buffer")) into one ESM file otherwise fails with "Dynamic require of buffer is not supported". Verified: the agent boots past all imports to the normal SIPHER_NETWORK env check -- no borsh SyntaxError, no dynamic-require error. Production build (tsc) + start are unchanged. --- packages/agent/package.json | 3 ++- packages/agent/tsup.config.ts | 20 ++++++++++++++++++++ pnpm-lock.yaml | 3 +++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 packages/agent/tsup.config.ts diff --git a/packages/agent/package.json b/packages/agent/package.json index 5261f3f..26ba40f 100644 --- a/packages/agent/package.json +++ b/packages/agent/package.json @@ -3,7 +3,7 @@ "version": "0.1.0", "type": "module", "scripts": { - "dev": "tsx watch src/index.ts", + "dev": "tsup --watch src --onSuccess 'node dist/index.js'", "build": "tsc", "start": "node dist/index.js", "test": "vitest run", @@ -33,6 +33,7 @@ "@types/supertest": "^6.0.3", "@types/ws": "^8.5.0", "supertest": "^7.2.2", + "tsup": "^8.3.6", "tsx": "^4.19.0", "typescript": "^5.7.0", "vitest": "^3.0.0" diff --git a/packages/agent/tsup.config.ts b/packages/agent/tsup.config.ts new file mode 100644 index 0000000..faf1465 --- /dev/null +++ b/packages/agent/tsup.config.ts @@ -0,0 +1,20 @@ +import { defineConfig } from 'tsup' + +// Dev/watch build for the agent entrypoint. +// tsx's ESM loader cannot instantiate @bonfida/spl-name-service@3.0.21's +// vendored borsh ESM bundle (see #253); building with tsup (esbuild) and +// running the output with plain `node` avoids that loader entirely. +export default defineConfig({ + entry: ['src/index.ts'], + format: ['esm'], + target: 'node22', + dts: false, + clean: true, + sourcemap: true, + splitting: false, + // Transpile only the agent's own source; let Node resolve node_modules at + // runtime. Bundling the transitive CJS chain (bs58 -> safe-buffer -> + // require("buffer")) into a single ESM file breaks with "Dynamic require + // not supported". Plain Node handles those deps (and Bonfida's ESM) fine. + skipNodeModulesBundle: true, +}) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ec279e6..2cf9f69 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -268,6 +268,9 @@ importers: supertest: specifier: ^7.2.2 version: 7.2.2 + tsup: + specifier: ^8.3.6 + version: 8.5.1(jiti@2.6.1)(postcss@8.5.6)(tsx@4.21.0)(typescript@5.9.3)(yaml@2.8.3) tsx: specifier: ^4.19.0 version: 4.21.0