Skip to content

[Bug]: Control UI blank screen — fs.constants.W_OK accessed at module scope breaks browser bundle #48062

@coolcgp

Description

@coolcgp

Bug type

Regression (worked before, now fails)

Summary

Control UI renders a blank dark screen because src/infra/tmp-openclaw-dir.ts evaluates fs.constants.W_OK at module scope, which crashes when the module is bundled into the browser via Vite (node:fs is externalized to undefined).

Steps to reproduce

  1. Git clone openclaw and checkout main at commit 0ed64f124.
  2. Run pnpm install && pnpm build && pnpm ui:build.
  3. Start the gateway and open the Control UI in a browser.
  4. The page loads with title "OpenClaw Control" but renders a blank/dark screen.
  5. Open browser DevTools console — see: Uncaught TypeError: Cannot read properties of undefined (reading 'W_OK').

Expected behavior

Control UI should load and render normally without JavaScript errors.

Actual behavior

The UI shows a blank dark screen. Browser console reports:

Uncaught TypeError: Cannot read properties of undefined (reading 'W_OK')

The error originates from the bundled index-*.js where src/infra/tmp-openclaw-dir.ts line 6 is evaluated at module load time:

const TMP_DIR_ACCESS_MODE = fs.constants.W_OK | fs.constants.X_OK;

Since Vite externalizes node:fs for the browser, fs is undefined, causing a fatal crash that prevents React from mounting.

Import chain from UI entry to crash:

ui/src/main.ts  app.ts  app-chat.ts  slash-command-executor.ts
   src/auto-reply/thinking.ts  src/plugins/provider-runtime.ts
     src/plugins/providers.ts  src/logging/subsystem.ts
       src/logging/logger.ts  src/infra/tmp-openclaw-dir.ts

OpenClaw version

2026.3.14 (commit 0ed64f1)

Operating system

macOS 13.5 (Darwin 22.6.0 x86_64)

Install method

git source (git clone + pnpm build + pnpm ui:build)

Model

N/A — this is a UI build/bundling issue, not model-related

Provider / routing chain

N/A — not provider-related

Config file / key location

No response

Additional provider/model setup details

No response

Logs, screenshots, and evidence

Browser console output:

Uncaught TypeError: Cannot read properties of undefined (reading 'W_OK')
    at index-CKFRmfl7.js:1198:0
The crash is at the top-level const TMP_DIR_ACCESS_MODE = fs.constants.W_OK | fs.constants.X_OK; in src/infra/tmp-openclaw-dir.ts line 6.

Impact and severity

Affected: All users accessing Control UI from git source installs Severity: High — Control UI is completely unusable (blank screen) Frequency: 100% reproducible Consequence: Cannot access any Control UI functionality (sessions, agents, channels, cron, etc.)

Additional information

Suggested fix: make TMP_DIR_ACCESS_MODE lazy by moving the fs.constants access into a function body, so it is only evaluated at call time (Node.js runtime) rather than at import time (browser bundle):

// Before (crashes in browser):
const TMP_DIR_ACCESS_MODE = fs.constants.W_OK | fs.constants.X_OK;

// After (safe — only evaluated when called in Node.js context):
function getTmpDirAccessMode(): number {
  return fs.constants.W_OK | fs.constants.X_OK;
}

Then replace the two usages of TMP_DIR_ACCESS_MODE (lines ~92 and ~158) with getTmpDirAccessMode().

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingregressionBehavior that previously worked and now fails

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions