openclaw - ✅(Solved) Fix [Bug]: ui:build fails because src/version.ts imports node:module (createRequire), which is not available in the browser [2 pull requests, 2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#60013Fetched 2026-04-08 02:37:26
View on GitHub
Comments
2
Participants
2
Timeline
7
Reactions
0
Participants
Timeline (top)
commented ×2labeled ×2closed ×1cross-referenced ×1

The UI build fails because src/version.ts imports createRequire from node:module, which is externalized to an empty stub in the browser environment, causing a missing export error.

Error Message

The UI build fails because src/version.ts imports createRequire from node:module, which is externalized to an empty stub in the browser environment, causing a missing export error. 3. Observe the build failure with the error: "createRequire" is not exported by "__vite-browser-external". Running pnpm ui:build fails with the following error: error during build: build error

Root Cause

The UI build fails because src/version.ts imports createRequire from node:module, which is externalized to an empty stub in the browser environment, causing a missing export error.

Fix Action

Fixed

PR fix notes

PR #60106: fix(ui): stub node:module in browser build to fix createRequire warning

Description (problem / solution / changelog)

Problem

src/version.ts imports createRequire from "node:module" at the module level:

import { createRequire } from "node:module";

In Vite browser builds, node:module is not available. Depending on the Vite version and configuration, this can cause a hard build error or a warning like:

Module "node:module" has been externalized for browser compatibility.
Cannot access "node:module.createRequire" in client code.

The existing readVersionFromJsonCandidates function already wraps createRequire usage in a try/catch and falls back to __OPENCLAW_VERSION__ (a build constant injected by Vite define), so it handles this gracefully — but only if the module resolves at all.

Fixes #60013

Solution

Add a resolve.alias in ui/vite.config.ts that maps "node:module" to a thin browser-safe stub:

// ui/src/shims/node-module.ts
export const createRequire: ((url: string) => any) | undefined = undefined;

The stub exports createRequire as undefined. The existing try/catch in readVersionFromJsonCandidates catches the resulting error and falls back to the injected build constant — no behavior change at runtime.

Files changed

  • ui/vite.config.ts — added resolve.alias for "node:module"
  • ui/src/shims/node-module.ts — new browser-safe stub (exports createRequire as undefined)

Changed files

  • ui/src/shims/node-module.ts (added, +7/-0)
  • ui/vite.config.ts (modified, +7/-0)

PR #60133: fix(ui): provide stub for node:module in browser builds

Description (problem / solution / changelog)

Summary

  • Fixes #60013 - ui:build fails because src/version.ts imports node:module (createRequire), which is not available in the browser

Changes

  • ui/vite.config.ts: Added resolve.alias to redirect node:module to browser stub
  • ui/src/polyfills/node-module-stub.ts: New stub that provides safe createRequire for browser builds

Test plan

  • pnpm ui:build succeeds without externalization warnings
  • pnpm test -- src/version.test.ts passes (12/12)
  • pnpm check passes

Fixes #60013

Changed files

  • ui/src/polyfills/node-module-stub.ts (added, +15/-0)
  • ui/vite.config.ts (modified, +9/-0)

Code Example

[plugin vite:resolve] Module "node:module" has been externalized for browser compatibility, imported by "/Users/xy_claw/Project/openclaw/src/version.ts".
 Build failed in 1.03s
error during build:
../src/version.ts (1:9): "createRequire" is not exported by "__vite-browser-external", imported by "../src/version.ts".
file: /Users/xy_claw/Project/openclaw/src/version.ts:1:9

1: import { createRequire } from "node:module";
^

---
RAW_BUFFERClick to expand / collapse

Bug type

Regression (worked before, now fails)

Beta release blocker

No

Summary

The UI build fails because src/version.ts imports createRequire from node:module, which is externalized to an empty stub in the browser environment, causing a missing export error.

Steps to reproduce

  1. Clone the repository and run pnpm install in the root directory.
  2. Run pnpm ui:build.
  3. Observe the build failure with the error: "createRequire" is not exported by "__vite-browser-external".

Expected behavior

The pnpm ui:build command should complete successfully without errors, producing a valid frontend build artifact. The version resolution logic should either be excluded from the browser bundle or implemented in a browser-compatible way (e.g., using injected build-time constants instead of createRequire).

Actual behavior

Running pnpm ui:build fails with the following error:

[plugin vite:resolve] Module "node:module" has been externalized for browser compatibility, imported by "/Users/xy_claw/Project/openclaw/src/version.ts".
✗ Build failed in 1.03s
error during build:
../src/version.ts (1:9): "createRequire" is not exported by "__vite-browser-external", imported by "../src/version.ts".
file: /Users/xy_claw/Project/openclaw/src/version.ts:1:9

1: import { createRequire } from "node:module";
^

OpenClaw version

2026.4.2

Operating system

macOS 26.2 (25C56)

Install method

No response

Model

build error

Provider / routing chain

none

Additional provider/model setup details

No response

Logs, screenshots, and evidence

Impact and severity

No response

Additional information

No response

extent analysis

TL;DR

The UI build fails due to the createRequire import from node:module being externalized to an empty stub in the browser environment, and a workaround is to modify the src/version.ts file to exclude the createRequire import or use a browser-compatible alternative.

Guidance

  • Identify the specific line of code causing the issue: import { createRequire } from "node:module"; in src/version.ts.
  • Consider using a build-time constant or a different approach to resolve versioning that is compatible with both Node.js and browser environments.
  • Modify the src/version.ts file to either exclude the createRequire import or provide a fallback implementation for the browser environment.
  • Verify the fix by running pnpm ui:build and checking for successful build completion without errors.

Example

// src/version.ts (example modification)
// Import createRequire only in Node.js environment
import { createRequire } from 'node:module';
// OR
// Use a build-time constant for version resolution
const VERSION = '2026.4.2'; // injected during build

Notes

The provided solution assumes that the createRequire import is not essential for the browser environment. If it is required, an alternative implementation or polyfill may be necessary.

Recommendation

Apply workaround: Modify the src/version.ts file to exclude or provide a fallback for the createRequire import, as this approach allows for a targeted fix without requiring a version upgrade or significant code changes.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

The pnpm ui:build command should complete successfully without errors, producing a valid frontend build artifact. The version resolution logic should either be excluded from the browser bundle or implemented in a browser-compatible way (e.g., using injected build-time constants instead of createRequire).

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING