环境 :Windows 10/11 + Node.js v24 + pnpm
项目 :OpenClaw(一个支持 Telegram、WhatsApp 等多平台的 AI 机器人框架)
目标:在不拥有私有源码的情况下,成功构建并运行核心功能
如无特殊说明,以下所有代码执行环境均为 window 系统下的powershell
上一篇讲述完 pnpm install,这一篇讲述 pnpm build
详情参考:
OpenClaw安装之(一)公司电脑下的企业防火墙的安装避坑指南:彻底解决 libsignal-node GitHub 下载失败问题 git 源码安装指南
OpenClaw 安装之(三)DeepSeek模型接入配置和详细配置参数
起因:看似简单的 pnpm install,却卡在构建阶段
执行完 pnpm install 后,按照常规流程运行:
powershell
pnpm build
结果报错:
text
scripts/bundle-a2ui.sh: line 31: node: command not found
❓ 问题:Bash 脚本在 Windows 上找不到 node
原因
OpenClaw 使用了一个 Unix 风格的 shell 脚本 bundle-a2ui.sh 来构建前端 UI(A2UI)。但在 Windows 上,该脚本由 Git Bash 执行,而 Git Bash 未继承系统 PATH ,导致无法找到 node.exe。
✅ 解决方案(采用)
放弃 Bash 脚本,改用纯 Node.js 脚本,实现跨平台兼容。
1)创建 scripts/bundle-a2ui.mjs:
js
// scripts/bundle-a2ui.mjs
// OpenClaw A2UI Bundle Placeholder Generator
// For public repository users who do not have access to private A2UI source code.
// This script creates a minimal valid ES module to satisfy TypeScript compilation.
import fs from 'node:fs';
import path from 'node:path';
import { createHash } from 'node:crypto';
import { fileURLToPath } from 'node:url';
// ── Resolve project root directory correctly on Windows and Unix ──
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const ROOT_DIR = path.resolve(__dirname, '..'); // openclaw/ root
// ── Define output paths ──
const OUTPUT_DIR = path.join(ROOT_DIR, 'src', 'canvas-host', 'a2ui');
const OUTPUT_FILE = path.join(OUTPUT_DIR, 'a2ui.bundle.js');
const HASH_FILE = path.join(OUTPUT_DIR, '.bundle.hash');
// ── Ensure output directory exists ──
fs.mkdirSync(OUTPUT_DIR, { recursive: true });
// ── Generate placeholder content (valid ES module) ──
const placeholderContent = `
// Auto-generated placeholder for A2UI
// Source code is not available in the public OpenClaw repository.
// This file exists only to satisfy build dependencies.
export const A2UI = {
version: '0.0.0-placeholder',
render: () => {
throw new Error('A2UI runtime is not available in this build.');
}
};
`.trim() + '\n';
// ── Write the bundle file ──
fs.writeFileSync(OUTPUT_FILE, placeholderContent);
// ── Compute and write hash to prevent unnecessary rebuilds ──
const hash = createHash('sha256').update(placeholderContent).digest('hex');
fs.writeFileSync(HASH_FILE, hash);
// ── Success message ──
console.log('✅ A2UI placeholder bundle created successfully.');
console.log(` Bundle: ${OUTPUT_FILE}`);
console.log(` Hash: ${HASH_FILE}`);
2)并在 package.json 中替换脚本:
D:\Program\OpenClaw\openclaw\package.json
文件下: .scripts.canvas:a2ui:bundle 修改为以下值。
json
{
"scripts": {
...,
"canvas:a2ui:bundle": "node --import tsx scripts/bundle-a2ui.mjs",
...
}
}
💡 此方案彻底绕过对
bash和node环境的依赖。
3)若 .\src\canvas-host\a2ui\index.html 文件不存在,则下载 index.html 到指定文件.\src\canvas-host\a2ui\ 。(否则会报错)
powershell
Invoke-WebRequest -Uri "https://raw.githubusercontent.com/openclaw/openclaw/main/src/canvas-host/a2ui/index.html" -OutFile .\src\canvas-host\a2ui\index.html
若无法下载,可下载文章资源。
成功构建!
再次运行:
powershell
pnpm build
输出:
powershell
PS D:\Program\OpenClaw\openclaw> pnpm build
> openclaw@2026.2.6-3 build D:\Program\OpenClaw\openclaw
> pnpm canvas:a2ui:bundle && tsdown && pnpm build:plugin-sdk:dts && node --import tsx scripts/write-plugin-sdk-entry-dts.ts && node --import tsx scripts/canvas-a2ui-copy.ts && node --import tsx scripts/copy-hook-metadata.ts && node --import tsx scripts/write-build-info.ts && node --import tsx scripts/write-cli-compat.ts
> openclaw@2026.2.6-3 canvas:a2ui:bundle D:\Program\OpenClaw\openclaw
> node --import tsx scripts/bundle-a2ui.mjs
...
...
ℹ dist\parse-timeout-DFSPLxpY.js 0.46 kB │ gzip: 0.26 kB
ℹ dist\prompt-style-Dc0C5HC9.js 0.44 kB │ gzip: 0.23 kB
ℹ dist\rolldown-runtime-Cbj13DAv.js 0.42 kB │ gzip: 0.28 kB
ℹ dist\helpers-D4gM-kkY.js 0.41 kB │ gzip: 0.26 kB ℹ dist\pairing-labels-Eo75HAld.js 0.26 kB │ gzip: 0.19 kB ℹ dist\prompts-CXLLIBwP.js 0.24 kB │ gzip: 0.17 kB ℹ dist\logging-CfEk_PnX.js 0.01 kB │ gzip: 0.03 kB ℹ 146 files, total: 6111.26 kB
✔ Build complete in 2918ms
🎉 构建成功!
接下来就能愉快使用官方的Powershell代码实现快速成功安装啦
powershell
CD D:\Program\OpenClaw
iwr -useb https://clawd.org.cn/install.ps1 | iex
安装成功
powershell
npm warn deprecated glob@11.1.0: Old versions of glob are not supported, and contain widely publicized security vulnerabilities, which have been fixed in the current version. Please update. Support for old versions may be purchased (at exorbitant rates) by contacting i@izs.me
npm warn deprecated tar@7.5.4: Old versions of tar are not supported, and contain widely publicized security vulnerabilities, which have been fixed in the current version. Please update. Support for old versions may be purchased (at exorbitant rates) by contacting i@izs.me
added 656 packages in 1m
[OK] OpenClaw installed successfully
[OK] Version: 0.1.4
[*] Starting onboarding...
🦞 Clawdbot-CN 0.1.4 (b161cdd) --- 我可以grep它,git blame它,并温柔地吐槽它------选择你的应对机制。
检测到 Windows 系统。
强烈推荐使用 WSL2;原生 Windows 未经测试且问题较多。
指南:https://docs.clawd.bot/windows
░████░█░░░░░█████░█░░░█░███░░████░░████░░▀█▀
█░░░░░█░░░░░█░░░█░█░█░█░█░░█░█░░░█░█░░░█░░█░
█░░░░░█░░░░░█████░█░█░█░█░░█░████░░█░░░█░░█░
█░░░░░█░░░░░█░░░█░█░█░█░█░░█░█░░█░░█░░░█░░█░
░████░█████░█░░░█░░█░█░░███░░████░░░███░░░█░
🦞 每日新鲜 🦞
T Clawdbot 安装引导
细分选项
Powershell
o 我理解这很强大且本质上存在风险。继续吗?
| Yes
|
o 安装引导模式
| 手动
|
o 您想要设置什么?
| 本地网关(此机器)
|
o 工作区目录
| D:/Program/OpenClaw/workspace
|
o 模型/认证提供商
| OpenAI
|
o OpenAI 认证方法
| OpenAI API key
|
o Enter OpenAI API key
| sk-xxxxxxxxxxxxxxx
|
o OpenAI API key -------------------------------------------------------------------------+
| |
| Saved OPENAI_API_KEY to C:\Users\panghuankun\.openclaw\.env for launchd compatibility. |
| |
+------------------------------------------------------------------------------------------+
|
o 默认模型
| 手动输入模型
|
o 默认模型
| deepseek/v3
|
o Model check --------------------------------------------------------------------------+
| |
| Model not found: deepseek/v3. Update agents.defaults.model or run /models list. |
| No auth configured for provider "deepseek". The agent may fail until credentials are |
| added. |
| |
+----------------------------------------------------------------------------------------+
|
o Gateway port
| 18789
|
o Gateway bind
| Loopback (127.0.0.1)
|
o Gateway auth
| Token
|
o Tailscale exposure
| Off
|
o Gateway token (blank to generate)
| Needed for multi-machine or non-loopback access
|
o 通道状态 -------------+
| |
| Telegram: 未配置 |
| WhatsApp: 未配置 |
| Discord: 未配置 |
| Google Chat: 未配置 |
| Feishu: 未配置 |
| Slack: 未配置 |
| Signal: 未配置 |
| iMessage: 未配置 |
| Feishu: 安装插件以启用 |
| |
+--------------------+
|
o 现在配置聊天通道吗?
| No
Updated C:\Users\panghuankun\.openclaw\openclaw.json
工作区正常:D:\Program\OpenClaw\workspace
会话正常:C:\Users\panghuankun\.openclaw\agents\main\sessions
|
o 技能状态 ------+
| |
| 符合条件:51 |
| 缺少需求:0 |
| 被允许列表阻止:0 |
| |
+-------------+
|
o 现在配置技能?(推荐)
| No
|
o 钩子 --------------------------------+
| |
| 钩子让您能够在代理命令发出时自动执行操作。 |
| 例如:在您发出/new时将会话上下文保存到内存中。 |
| |
| 了解更多:https://docs.clawd.bot/hooks |
| |
+-------------------------------------+
|
o 启用钩子?
| 暂时跳过, 🔗 boot-md
|
o 钩子已配置 ------------------------------+
| |
| 启用了 1 个钩子:boot-md |
| |
| 您可以稍后使用以下命令管理钩子: |
| openclaw-cn hooks list |
| openclaw-cn hooks enable <name> |
| openclaw-cn hooks disable <name> |
| |
+--------------------------------------+
|
o 安装网关服务(推荐)
| Yes
|
o 网关服务运行时
| Node (recommended)
|
0 Installing Gateway service...
Installed Scheduled Task: Openclaw Gateway
Task script: C:\Users\panghuankun\.openclaw\gateway.cmd
o 网关服务已安装。
|
o
Health check failed: gateway closed (1006 abnormal closure (no close frame)): no close reason
Gateway target: ws://127.0.0.1:18789
Source: local loopback
Config: C:\Users\panghuankun\.openclaw\openclaw.json
Bind: loopback
|
o Health check help ------------------------------+
| |
| Docs: |
| https://docs.clawd.bot/gateway/health |
| https://docs.clawd.bot/gateway/troubleshooting |
| |
+--------------------------------------------------+
|
o 可选应用 ---------------+
| |
| 为额外功能添加节点: |
| - macOS应用(系统+通知) |
| - iOS应用(相机/画布) |
| - Android应用(相机/画布) |
| |
+----------------------+
|
o 控制界面 -------------------------------------------------------------------------------+
| |
| 网页界面:http://127.0.0.1:18789/ |
| 网页界面(带令牌):http://127.0.0.1:18789/?token=undefined |
| 网关WS:ws://127.0.0.1:18789 |
| 网关:未检测到 (gateway closed (1006 abnormal closure (no close frame)): no close reason) |
| 文档:https://docs.clawd.bot/web/control-ui |
| |
+--------------------------------------------------------------------------------------+
|
o 工作区备份 ----------------------------------------------+
| |
| 备份您的智能体工作区。 |
| 文档:https://docs.clawd.bot/concepts/agent-workspace |
| |
+------------------------------------------------------+
|
o 安全 --------------------------------------------------------+
| |
| 在您的计算机上运行智能体是有风险的------加强您的设置:https://docs.clawd.bot/security |
| |
+-------------------------------------------------------------+
|
o 仪表盘就绪 ----------------------------------------------+
| |
| 仪表盘链接(带令牌):http://127.0.0.1:18789/?token=undefined |
| 已在浏览器中打开。保留该标签页以控制Clawdbot。 |
| |
+------------------------------------------------------+
|
o 网络搜索(可选) ---------------------------------------------------------------+
| |
| 如果希望您的智能体能够搜索网络,则需要API密钥。 |
| |
| Clawdbot使用Brave Search作为`web_search`工具。没有Brave Search API密钥,网络搜索将无法工作。 |
| |
| 交互式设置: |
| - 运行:openclaw-cn configure --section web |
| - 启用web_search并粘贴您的Brave Search API密钥 |
| |
| 替代方案:在网关环境中设置BRAVE_API_KEY(无需更改配置)。 |
| 文档:https://docs.clawd.bot/tools/web |
| |
+--------------------------------------------------------------------------+
|
o 接下来 -----------------------------------------+
| |
| 接下来:https://clawd.bot/showcase("人们正在构建什么")。 |
| |
+-----------------------------------------------+
|
--- 安装引导完成。仪表盘已使用您的令牌打开;保留该标签页以控制Clawdbot。
Installation complete!
以上配置完之后,打开会报gateway的token错误。
解决:添加gateway的token:token自定义设置。
powershell
cd D:\Program\OpenClaw\openclaw
openclaw-cn gateway stop
openclaw-cn gateway --token 65s4df32s3d2f
完成后打开浏览器,token可自行设置。
输入:http://127.0.0.1:18789?token=65s4df32s3d2f
即可打开网页。
注,此时对话还不能正常使用。但是已经能正常展示页面了。