From 1e3e270b44fe7490f768490a5a37439dfeb48501 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Feb 2026 14:34:54 +0000 Subject: [PATCH] fix: include package.json in bundle dir to prevent ENOENT crash on startup @mariozechner/pi-coding-agent reads package.json at module load time (config.js:139) via getPackageDir(), which walks up from __dirname looking for package.json. In production, the bundled index.js runs from a directory with no package.json, causing a fatal ENOENT that crashes the server. Write a package.json (with type and version) into the bundle output directory so it ships alongside the production bundle. Also add version to the dist/server/package.json for compiled binary deployments. Slack thread: https://felafax.slack.com/archives/C0AF85H7PK8/p1772028629327479 https://claude.ai/code/session_01RjbFDanzVw73iiFAhh59Kp --- scripts/build/server.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/scripts/build/server.ts b/scripts/build/server.ts index 628cdb75..ddebe73a 100644 --- a/scripts/build/server.ts +++ b/scripts/build/server.ts @@ -209,6 +209,14 @@ async function bundleWithPlugins( for (const entry of result.logs) log.error(String(entry)) throw new Error('Bundle with plugins failed') } + + // Write package.json into the bundle directory so it's available at runtime. + // Required by @mariozechner/pi-coding-agent which reads package.json at module + // load time via getPackageDir() to extract version and config. + writeFileSync( + join(BUNDLE_DIR, 'package.json'), + JSON.stringify({ type: 'module', version }), + ) } async function compileTarget( @@ -299,7 +307,10 @@ async function build(config: BuildConfig): Promise { mkdirSync('dist/server', { recursive: true }) // Bun compiled binaries require a package.json next to the executable - writeFileSync('dist/server/package.json', JSON.stringify({ type: 'module' })) + writeFileSync( + 'dist/server/package.json', + JSON.stringify({ type: 'module', version }), + ) if (shouldUploadSourceMaps) { log.step('Building source maps...')