在windows10下编译OpenClaw需要修改
9 2026-03-23 10:04 2026-03-23 10:04
我是在windows10环境下构建OpenClaw。遇到了. prepare$ command -v git >/dev/null 2>&1 && git rev-parse --is-inside-work-tree >/dev/null 2>&1 && git config core.hooksPath git-hooks || exit 0 . prepare: The system cannot find the path specified.
这个错误是因为 Windows CMD 不支持 Linux 命令语法(
>/dev/null 2>&1 是 Bash 的重定向语法)。问题原因
prepare 脚本中的命令是 Unix/Linux 风格:bash
复制
command -v git >/dev/null 2>&1 && ...
在 Windows CMD/PowerShell 中:
-
>/dev/null❌ 不支持 -
2>&1❌ 不支持 -
command -v❌ 不支持
解决方案
方案一:跳过 prepare 脚本(最快)
powershell
复制
pnpm install --ignore-scripts
然后手动执行构建:
powershell
复制
pnpm ui:build
pnpm build
方案二:使用 Git Bash 环境
如果你有 Git for Windows(自带 Git Bash):
-
打开 Git Bash(在开始菜单找)
-
进入项目目录:bash
-
复制
cd /e/Users/21/5.工作/养龙虾/openclaw源代码/openclaw -
执行:bash
-
复制
pnpm install && pnpm ui:build && pnpm build
方案三:修改 package.json(根治)
找到
package.json 中的 scripts.prepare,改成 Windows 兼容版本:原来(不兼容):
JSON
复制
{
"scripts": {
"prepare": "command -v git >/dev/null 2>&1 && git rev-parse --is-inside-work-tree >/dev/null 2>&1 && git config core.hooksPath git-hooks || exit 0"
}
}
修改后(兼容 Windows):
JSON
复制
{
"scripts": {
"prepare": "git config core.hooksPath git-hooks 2>nul || exit 0"
}
}
然后重新安装:
powershell
复制
pnpm install
推荐做法
对于 Windows 10 构建 OpenClaw:
powershell
复制
# 1. 跳过有问题的 prepare 脚本
pnpm install --ignore-scripts
# 2. 手动设置 git hooks(可选)
git config core.hooksPath git-hooks
# 3. 继续构建
pnpm ui:build
pnpm build
我选用的方案3
全部评论