From ee021da8e8fb4f1a7e30d5a94295a427019affd1 Mon Sep 17 00:00:00 2001 From: kryptobaseddev Date: Fri, 12 Jun 2026 12:06:51 -0700 Subject: [PATCH] fix(T12011): guard lafs health createRequire against Vite SSR bundler path shift MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Root cause: packages/lafs/src/health/index.ts used createRequire() with relative paths (../../package.json, ../../../package.json) to read the package version. These relative paths are correct from the source/dist location but break when Vite's SSR bundler inlines the module into .svelte-kit/output/server/chunks/src2.js — the bundled file lives at a different depth so both require() calls throw MODULE_NOT_FOUND and the uncaught error aborts the entire vite build. Fix: add an outer try/catch with a safe { version: 'unknown' } default so that a resolve failure in a bundled context never prevents the health middleware from loading. The inner try/catch continues to attempt both relative paths so native (non-bundled) consumers are unaffected. Local proof: reproduced the exact "Cannot find module '../../../package.json'" / ERR_PNPM_RECURSIVE_RUN_FIRST_FAIL error locally, then confirmed the studio build passes after this change: - pnpm --filter @cleocode/studio run build -> success - node packages/cleo/scripts/copy-studio-dist.mjs -> studio-dist/ staged - packages/cleo/studio-dist/client/ present - packages/cleo/studio-dist/client/_app/ present - node scripts/assert-cleo-tarball.mjs -> All assertions passed - node scripts/lint-deployed-template-parity.mjs -> PASS - pnpm biome ci . -> No fixes applied Co-Authored-By: Claude Fable 5 --- packages/lafs/src/health/index.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/lafs/src/health/index.ts b/packages/lafs/src/health/index.ts index c376d9221..9d5f9cb8d 100644 --- a/packages/lafs/src/health/index.ts +++ b/packages/lafs/src/health/index.ts @@ -9,11 +9,21 @@ import { createRequire } from 'node:module'; const require = createRequire(import.meta.url); -let pkg: { version: string }; +// T12011: Both require() calls use relative paths that are valid when running +// from the source/dist location but break when Vite's SSR bundler inlines this +// module into a different output path (e.g. .svelte-kit/output/server/chunks/). +// The outer catch guarantees that a version-resolution failure in a bundled +// context never prevents the health middleware from loading. +let pkg: { version: string } = { version: 'unknown' }; try { - pkg = require('../../package.json'); + try { + pkg = require('../../package.json') as { version: string }; + } catch { + pkg = require('../../../package.json') as { version: string }; + } } catch { - pkg = require('../../../package.json'); + // Running from a bundled SSR context where relative require() paths do not + // resolve — version falls back to 'unknown'. Health checks still work. } /** Configuration for the {@link healthCheck} middleware. */