fix(T12011): guard lafs health createRequire against Vite SSR bundler path shift#1100
Merged
Conversation
… path shift
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 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root cause (file:line + why CI-only)
packages/lafs/src/health/index.tslines 11-17: the module usescreateRequire()with relative paths to read its package version at startup:When Vite's SvelteKit SSR bundler inlines
@cleocode/lafsinto.svelte-kit/output/server/chunks/src2.js(due tonoExternal: [/^@cleocode\//]invite.config.ts), the relative paths are preserved but now resolve relative to the bundled file's location — not the source file. Bothrequire()calls throwMODULE_NOT_FOUND. The innercatchonly catches the first failure and re-throws from the second; the error propagates uncaught and killsvite build.This is CI-only because a local dev
vite devuses unbundled module resolution (import fromnode_modules/@cleocode/lafsdirectly), while only the productionvite buildbundles@cleocode/*packages via SSR inlining.The precise error chain in release run 27435975568:
Fix
Add an outer
try/catchwith a safe{ version: 'unknown' }default so that a resolve failure in a bundled SSR context never prevents the health middleware from loading. The innertry/catchstill attempts both relative paths so native (non-bundled) consumers are unaffected.Changed file:
packages/lafs/src/health/index.ts— 1 file, +13/-3 lines.Staging shape (confirmed correct, no change needed)
adapter-nodewithout: 'build'emits:copy-studio-dist.mjscopiespackages/studio/build/→packages/cleo/studio-dist/.The workflow assertion checks
packages/cleo/studio-dist/client— this matches. No change to staging shape or workflow assertion needed.Local end-to-end proof
Checklist
lafs/src/health/index.tsrelativerequire()breaks when Vite SSR inlines the moduletry/catchwith{ version: 'unknown' }safe defaultassert-cleo-tarball.mjsgate passes🤖 Generated with Claude Code