Repository navigation
fix(ui): defer fs.constants eval to prevent browser bundle crash - #48930
Conversation
Greptile SummaryThis PR fixes a browser bundle crash caused by
Confidence Score: 5/5
Last reviewed commit: af3ef34 |
|
Codex deep review: this still looks like a valid, narrow fix. What I verified on current
I would still want this refreshed before landing because the PR is old and CI currently reports |
The control UI crashes on load with:
TypeError: Cannot read properties of undefined (reading 'W_OK')
Root cause: `tmp-openclaw-dir.ts` evaluates `fs.constants.W_OK` at
module load time via a top-level const. When Vite bundles this file
for the browser, `node:fs` resolves to a stub where `fs.constants`
is undefined, so the const initializer throws immediately on import.
The import chain that pulls this into the browser bundle:
thinking.ts → provider-runtime.ts → providers.ts
→ subsystem.ts → logger.ts → tmp-openclaw-dir.ts
Fix: move TMP_DIR_ACCESS_MODE inside resolvePreferredOpenClawTmpDir()
so fs.constants is only accessed when the function is called in a
Node.js context, not when the module is imported.
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
af3ef34 to
2510bec
Compare
|
Landed. Thanks @Valentinws. Codex follow-up added a regression test that bundles Local verification before merge:
Note: full Merge commit: 4a68fa3 |
Summary
The control UI shows a black screen and throws in the browser console:
Root cause:
src/infra/tmp-openclaw-dir.tsevaluatesfs.constants.W_OKat module load time via a top-levelconst. When Vite bundles this for the browser,node:fsresolves to a stub wherefs.constantsisundefined, so the initializer throws on import before any code runs.The import chain introduced in a33caab pulls this into the browser bundle:
Note:
logger.tsalready has acanUseNodeFs()guard that prevents callingresolvePreferredOpenClawTmpDir()in the browser — but that guard is never reached because the crash happens earlier whentmp-openclaw-dir.tsis first imported.Fix: move
TMP_DIR_ACCESS_MODEinsideresolvePreferredOpenClawTmpDir()sofs.constantsis only accessed when the function is called (Node.js runtime), not when the module is imported (browser bundle).Test plan
src/infra/tmp-openclaw-dir.test.tspasses (all 20 tests)W_OKTypeError🤖 Generated with Claude Code