脚本内容如下
# Moltbot Installer for Windows
# Usage: iwr -useb https://molt.bot/install.ps1 | iex
# & ([scriptblock]::Create((iwr -useb https://molt.bot/install.ps1 ))) -Tag beta -NoOnboard -DryRun
param(
[string]$Tag = "latest",
[ValidateSet("npm", "git")]
[string]$InstallMethod = "npm",
[string]$GitDir,
[switch]$NoOnboard,
[switch]$NoGitUpdate,
[switch]$DryRun
)
$ErrorActionPreference = "Stop"
Write-Host ""
Write-Host " Moltbot Installer" -ForegroundColor Cyan
Write-Host ""
# Check if running in PowerShell
if ($PSVersionTable.PSVersion.Major -lt 5) {
Write-Host "Error: PowerShell 5+ required" -ForegroundColor Red
exit 1
}
Write-Host "[OK] Windows detected" -ForegroundColor Green
if (-not $PSBoundParameters.ContainsKey("InstallMethod")) {
if (-not [string]::IsNullOrWhiteSpace($env:CLAWDBOT_INSTALL_METHOD)) {
$InstallMethod = $env:CLAWDBOT_INSTALL_METHOD
}
}
if (-not $PSBoundParameters.ContainsKey("GitDir")) {
if (-not [string]::IsNullOrWhiteSpace($env:CLAWDBOT_GIT_DIR)) {
$GitDir = $env:CLAWDBOT_GIT_DIR
}
}
if (-not $PSBoundParameters.ContainsKey("NoOnboard")) {
if ($env:CLAWDBOT_NO_ONBOARD -eq "1") {
$NoOnboard = $true
}
}
if (-not $PSBoundParameters.ContainsKey("NoGitUpdate")) {
if ($env:CLAWDBOT_GIT_UPDATE -eq "0") {
$NoGitUpdate = $true
}
}
if (-not $PSBoundParameters.ContainsKey("DryRun")) {
if ($env:CLAWDBOT_DRY_RUN -eq "1") {
$DryRun = $true
}
}
if ([string]::IsNullOrWhiteSpace($GitDir)) {
$userHome = [Environment]::GetFolderPath("UserProfile")
$GitDir = (Join-Path $userHome "clawdbot")
}
# Check for Node.js
function Check-Node {
try {
$nodeVersion = (node -v 2>$null)
if ($nodeVersion) {
$version = [int]($nodeVersion -replace 'v(\d+)\..*', '$1')
if ($version -ge 22) {
Write-Host "[OK] Node.js $nodeVersion found" -ForegroundColor Green
return $true
} else {
Write-Host "[!] Node.js $nodeVersion found, but v22+ required" -ForegroundColor Yellow
return $false
}
}
} catch {
Write-Host "[!] Node.js not found" -ForegroundColor Yellow
return $false
}
return $false
}
# Install Node.js
function Install-Node {
Write-Host "[*] Installing Node.js..." -ForegroundColor Yellow
# Try winget first (Windows 11 / Windows 10 with App Installer)
if (Get-Command winget -ErrorAction SilentlyContinue) {
Write-Host " Using winget..." -ForegroundColor Gray
winget install OpenJS.NodeJS.LTS --accept-package-agreements --accept-source-agreements
# Refresh PATH
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
Write-Host "[OK] Node.js installed via winget" -ForegroundColor Green
return
}
# Try Chocolatey
if (Get-Command choco -ErrorAction SilentlyContinue) {
Write-Host " Using Chocolatey..." -ForegroundColor Gray
choco install nodejs-lts -y
# Refresh PATH
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
Write-Host "[OK] Node.js installed via Chocolatey" -ForegroundColor Green
return
}
# Try Scoop
if (Get-Command scoop -ErrorAction SilentlyContinue) {
Write-Host " Using Scoop..." -ForegroundColor Gray
scoop install nodejs-lts
Write-Host "[OK] Node.js installed via Scoop" -ForegroundColor Green
return
}
# Manual download fallback
Write-Host ""
Write-Host "Error: Could not find a package manager (winget, choco, or scoop)" -ForegroundColor Red
Write-Host ""
Write-Host "Please install Node.js 22+ manually:" -ForegroundColor Yellow
Write-Host " https://nodejs.org/en/download/ " -ForegroundColor Cyan
Write-Host ""
Write-Host "Or install winget (App Installer) from the Microsoft Store." -ForegroundColor Gray
exit 1
}
# Check for existing Moltbot installation
function Check-ExistingMoltbot {
try {
$null = Get-Command clawdbot -ErrorAction Stop
Write-Host "[*] Existing Moltbot installation detected" -ForegroundColor Yellow
return $true
} catch {
return $false
}
}
function Check-Git {
try {
$null = Get-Command git -ErrorAction Stop
return $true
} catch {
return $false
}
}
function Require-Git {
if (Check-Git) { return }
Write-Host ""
Write-Host "Error: Git is required for --InstallMethod git." -ForegroundColor Red
Write-Host "Install Git for Windows:" -ForegroundColor Yellow
Write-Host " https://git-scm.com/download/win " -ForegroundColor Cyan
Write-Host "Then re-run this installer." -ForegroundColor Yellow
exit 1
}
function Ensure-MoltbotOnPath {
if (Get-Command clawdbot -ErrorAction SilentlyContinue) {
return $true
}
$npmPrefix = $null
try {
$npmPrefix = (npm config get prefix 2>$null).Trim()
} catch {
$npmPrefix = $null
}
if (-not [string]::IsNullOrWhiteSpace($npmPrefix)) {
$npmBin = Join-Path $npmPrefix "bin"
$userPath = [Environment]::GetEnvironmentVariable("Path", "User")
if (-not ($userPath -split ";" | Where-Object { $_ -ieq $npmBin })) {
[Environment]::SetEnvironmentVariable("Path", "$userPath;$npmBin", "User")
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
Write-Host "[!] Added $npmBin to user PATH (restart terminal if command not found)" -ForegroundColor Yellow
}
if (Test-Path (Join-Path $npmBin "clawdbot.cmd")) {
return $true
}
}
Write-Host "[!] clawdbot is not on PATH yet." -ForegroundColor Yellow
Write-Host "Restart PowerShell or add the npm global bin folder to PATH." -ForegroundColor Yellow
if ($npmPrefix) {
Write-Host "Expected path: $npmPrefix\\bin" -ForegroundColor Cyan
} else {
Write-Host "Hint: run \"npm config get prefix\" to find your npm global path." -ForegroundColor Gray
}
return $false
}
function Ensure-Pnpm {
if (Get-Command pnpm -ErrorAction SilentlyContinue) {
return
}
if (Get-Command corepack -ErrorAction SilentlyContinue) {
try {
corepack enable | Out-Null
corepack prepare pnpm@latest --activate | Out-Null
if (Get-Command pnpm -ErrorAction SilentlyContinue) {
Write-Host "[OK] pnpm installed via corepack" -ForegroundColor Green
return
}
} catch {
# fallthrough to npm install
}
}
Write-Host "[*] Installing pnpm..." -ForegroundColor Yellow
npm install -g pnpm
Write-Host "[OK] pnpm installed" -ForegroundColor Green
}
# Install Moltbot
function Install-Moltbot {
if ([string]::IsNullOrWhiteSpace($Tag)) {
$Tag = "latest"
}
Write-Host "[*] Installing Moltbot@$Tag..." -ForegroundColor Yellow
$prevLogLevel = $env:NPM_CONFIG_LOGLEVEL
$prevUpdateNotifier = $env:NPM_CONFIG_UPDATE_NOTIFIER
$prevFund = $env:NPM_CONFIG_FUND
$prevAudit = $env:NPM_CONFIG_AUDIT
$env:NPM_CONFIG_LOGLEVEL = "error"
$env:NPM_CONFIG_UPDATE_NOTIFIER = "false"
$env:NPM_CONFIG_FUND = "false"
$env:NPM_CONFIG_AUDIT = "false"
try {
$npmOutput = npm install -g "clawdbot@$Tag" 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Host "[!] npm install failed" -ForegroundColor Red
if ($npmOutput -match "spawn git" -or $npmOutput -match "ENOENT.*git") {
Write-Host "Error: git is missing from PATH." -ForegroundColor Red
Write-Host "Install Git for Windows, then reopen PowerShell and retry:" -ForegroundColor Yellow
Write-Host " https://git-scm.com/download/win " -ForegroundColor Cyan
} else {
Write-Host "Re-run with verbose output to see the full error:" -ForegroundColor Yellow
Write-Host " iwr -useb https://molt.bot/install.ps1 | iex" -ForegroundColor Cyan
}
$npmOutput | ForEach-Object { Write-Host $_ }
exit 1
}
} finally {
$env:NPM_CONFIG_LOGLEVEL = $prevLogLevel
$env:NPM_CONFIG_UPDATE_NOTIFIER = $prevUpdateNotifier
$env:NPM_CONFIG_FUND = $prevFund
$env:NPM_CONFIG_AUDIT = $prevAudit
}
Write-Host "[OK] Moltbot installed" -ForegroundColor Green
}
# Install Moltbot from GitHub
function Install-MoltbotFromGit {
param(
[string]$RepoDir,
[switch]$SkipUpdate
)
Require-Git
Ensure-Pnpm
$repoUrl = "https://github.com/clawdbot/clawdbot.git "
Write-Host "[*] Installing Moltbot from GitHub ($repoUrl)..." -ForegroundColor Yellow
if (-not (Test-Path $RepoDir)) {
git clone $repoUrl $RepoDir
}
if (-not $SkipUpdate) {
if (-not (git -C $RepoDir status --porcelain 2>$null)) {
git -C $RepoDir pull --rebase 2>$null
} else {
Write-Host "[!] Repo is dirty; skipping git pull" -ForegroundColor Yellow
}
} else {
Write-Host "[!] Git update disabled; skipping git pull" -ForegroundColor Yellow
}
Remove-LegacySubmodule -RepoDir $RepoDir
pnpm -C $RepoDir install
if (-not (pnpm -C $RepoDir ui:build)) {
Write-Host "[!] UI build failed; continuing (CLI may still work)" -ForegroundColor Yellow
}
pnpm -C $RepoDir build
$binDir = Join-Path $env:USERPROFILE ".local\\bin"
if (-not (Test-Path $binDir)) {
New-Item -ItemType Directory -Force -Path $binDir | Out-Null
}
$cmdPath = Join-Path $binDir "clawdbot.cmd"
$cmdContents = "@echo off`r`nnode ""$RepoDir\\dist\\entry.js"" %*`r`n"
Set-Content -Path $cmdPath -Value $cmdContents -NoNewline
$userPath = [Environment]::GetEnvironmentVariable("Path", "User")
if (-not ($userPath -split ";" | Where-Object { $_ -ieq $binDir })) {
[Environment]::SetEnvironmentVariable("Path", "$userPath;$binDir", "User")
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
Write-Host "[!] Added $binDir to user PATH (restart terminal if command not found)" -ForegroundColor Yellow
}
Write-Host "[OK] Moltbot wrapper installed to $cmdPath" -ForegroundColor Green
Write-Host "[i] This checkout uses pnpm. For deps, run: pnpm install (avoid npm install in the repo)." -ForegroundColor Gray
}
# Run doctor for migrations (safe, non-interactive)
function Run-Doctor {
Write-Host "[*] Running doctor to migrate settings..." -ForegroundColor Yellow
try {
clawdbot doctor --non-interactive
} catch {
# Ignore errors from doctor
}
Write-Host "[OK] Migration complete" -ForegroundColor Green
}
function Get-LegacyRepoDir {
if (-not [string]::IsNullOrWhiteSpace($env:CLAWDBOT_GIT_DIR)) {
return $env:CLAWDBOT_GIT_DIR
}
$userHome = [Environment]::GetFolderPath("UserProfile")
return (Join-Path $userHome "clawdbot")
}
function Remove-LegacySubmodule {
param(
[string]$RepoDir
)
if ([string]::IsNullOrWhiteSpace($RepoDir)) {
$RepoDir = Get-LegacyRepoDir
}
$legacyDir = Join-Path $RepoDir "Peekaboo"
if (Test-Path $legacyDir) {
Write-Host "[!] Removing legacy submodule checkout: $legacyDir" -ForegroundColor Yellow
Remove-Item -Recurse -Force $legacyDir
}
}
# Main installation flow
function Main {
if ($InstallMethod -ne "npm" -and $InstallMethod -ne "git") {
Write-Host "Error: invalid -InstallMethod (use npm or git)." -ForegroundColor Red
exit 2
}
if ($DryRun) {
Write-Host "[OK] Dry run" -ForegroundColor Green
Write-Host "[OK] Install method: $InstallMethod" -ForegroundColor Green
if ($InstallMethod -eq "git") {
Write-Host "[OK] Git dir: $GitDir" -ForegroundColor Green
if ($NoGitUpdate) {
Write-Host "[OK] Git update: disabled" -ForegroundColor Green
} else {
Write-Host "[OK] Git update: enabled" -ForegroundColor Green
}
}
if ($NoOnboard) {
Write-Host "[OK] Onboard: skipped" -ForegroundColor Green
}
return
}
Remove-LegacySubmodule -RepoDir $RepoDir
# Check for existing installation
$isUpgrade = Check-ExistingMoltbot
# Step 1: Node.js
if (-not (Check-Node)) {
Install-Node
# Verify installation
if (-not (Check-Node)) {
Write-Host ""
Write-Host "Error: Node.js installation may require a terminal restart" -ForegroundColor Red
Write-Host "Please close this terminal, open a new one, and run this installer again." -ForegroundColor Yellow
exit 1
}
}
$finalGitDir = $null
# Step 2: Moltbot
if ($InstallMethod -eq "git") {
$finalGitDir = $GitDir
Install-MoltbotFromGit -RepoDir $GitDir -SkipUpdate:$NoGitUpdate
} else {
Install-Moltbot
}
if (-not (Ensure-MoltbotOnPath)) {
Write-Host "Install completed, but Moltbot is not on PATH yet." -ForegroundColor Yellow
Write-Host "Open a new terminal, then run: clawdbot doctor" -ForegroundColor Cyan
return
}
# Step 3: Run doctor for migrations if upgrading or git install
if ($isUpgrade -or $InstallMethod -eq "git") {
Run-Doctor
}
$installedVersion = $null
try {
$installedVersion = (clawdbot --version 2>$null).Trim()
} catch {
$installedVersion = $null
}
if (-not $installedVersion) {
try {
$npmList = npm list -g --depth 0 --json 2>$null | ConvertFrom-Json
if ($npmList -and $npmList.dependencies -and $npmList.dependencies.clawdbot -and $npmList.dependencies.clawdbot.version) {
$installedVersion = $npmList.dependencies.clawdbot.version
}
} catch {
$installedVersion = $null
}
}
Write-Host ""
if ($installedVersion) {
Write-Host "Moltbot installed successfully ($installedVersion)!" -ForegroundColor Green
} else {
Write-Host "Moltbot installed successfully!" -ForegroundColor Green
}
Write-Host ""
if ($isUpgrade) {
$updateMessages = @(
"Leveled up! New skills unlocked. You're welcome.",
"Fresh code, same lobster. Miss me?",
"Back and better. Did you even notice I was gone?",
"Update complete. I learned some new tricks while I was out.",
"Upgraded! Now with 23% more sass.",
"I've evolved. Try to keep up.",
"New version, who dis? Oh right, still me but shinier.",
"Patched, polished, and ready to pinch. Let's go.",
"The lobster has molted. Harder shell, sharper claws.",
"Update done! Check the changelog or just trust me, it's good.",
"Reborn from the boiling waters of npm. Stronger now.",
"I went away and came back smarter. You should try it sometime.",
"Update complete. The bugs feared me, so they left.",
"New version installed. Old version sends its regards.",
"Firmware fresh. Brain wrinkles: increased.",
"I've seen things you wouldn't believe. Anyway, I'm updated.",
"Back online. The changelog is long but our friendship is longer.",
"Upgraded! Peter fixed stuff. Blame him if it breaks.",
"Molting complete. Please don't look at my soft shell phase.",
"Version bump! Same chaos energy, fewer crashes (probably)."
)
Write-Host (Get-Random -InputObject $updateMessages) -ForegroundColor Gray
Write-Host ""
} else {
$completionMessages = @(
"Ahh nice, I like it here. Got any snacks? ",
"Home sweet home. Don't worry, I won't rearrange the furniture.",
"I'm in. Let's cause some responsible chaos.",
"Installation complete. Your productivity is about to get weird.",
"Settled in. Time to automate your life whether you're ready or not.",
"Cozy. I've already read your calendar. We need to talk.",
"Finally unpacked. Now point me at your problems.",
"cracks claws Alright, what are we building?",
"The lobster has landed. Your terminal will never be the same.",
"All done! I promise to only judge your code a little bit."
)
Write-Host (Get-Random -InputObject $completionMessages) -ForegroundColor Gray
Write-Host ""
}
if ($InstallMethod -eq "git") {
Write-Host "Source checkout: $finalGitDir" -ForegroundColor Cyan
Write-Host "Wrapper: $env:USERPROFILE\\.local\\bin\\clawdbot.cmd" -ForegroundColor Cyan
Write-Host ""
}
if ($isUpgrade) {
Write-Host "Upgrade complete. Run " -NoNewline
Write-Host "clawdbot doctor" -ForegroundColor Cyan -NoNewline
Write-Host " to check for additional migrations."
} else {
if ($NoOnboard) {
Write-Host "Skipping onboard (requested). Run " -NoNewline
Write-Host "clawdbot onboard" -ForegroundColor Cyan -NoNewline
Write-Host " later."
} else {
Write-Host "Starting setup..." -ForegroundColor Cyan
Write-Host ""
clawdbot onboard
}
}
}
Main
排查 npm 安装失败与手动安装步骤
用户在安装 Moltbot(也称为 Clawdbot)时遇到了问题。从错误截图中可以看到:
- 用户运行的是
iwr -useb https://clawd.bot/install.ps1 | iex - 安装脚本能检测到 Windows 和 Node.js v24.13.0
- 但在执行
npm install -g clawdbot@latest时失败了 - 错误信息是
npm error code ENOENT,具体在运行"C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_mo ...时出错
ENOENT 错误通常表示文件或目录不存在。很有趣的是,从截图中可以看到 Node.js 确实被检测到了(v24.13.0),但 npm 安装仍然失败。
用户提供了完整的 PowerShell 脚本内容。让我分析一下脚本中的
Install-Moltbot 函数。在脚本中,
Install-Moltbot 函数执行以下操作:- 设置环境变量以减少 npm 输出噪音
- 运行
npm install -g "clawdbot@$Tag" - 如果失败,会检查错误输出中是否包含 "spawn git" 或 "ENOENT.*git"(这表明可能是缺少 git)
但从截图来看,错误信息被截断了。错误发生在 npm 尝试执行 Node 时,显示的是
node.exe 路径和 node_mo...,很可能是在尝试执行 node_modules 中的某个文件或 npm 自身的脚本。考虑到:
- 用户使用的是命令
iwr -useb https://clawd.bot/install.ps1,但脚本开头写的是https://molt.bot/install.ps1 - 脚本中的日志显示 "Moltbot Installer"
- 包名是
clawdbot
看起来这是同一个工具的不同品牌名称。
clawd.bot 可能是新的域名。现在,错误的关键是
ENOENT。在 Windows 上,npm 出现 ENOENT 的可能原因包括:- npm 缓存损坏
- 全局安装路径问题
- 权限问题(虽然通常在 Windows 上不像 Linux 那样常见,除非在受保护的目录)
- npm 安装本身损坏
看看错误行:
plain
Copy
+ & "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_mo ...这看起来 npm 正在尝试运行一个被截断为
node_mo 的路径。这很可能是 "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" 或类似的东西。如果
node_modules 目录或 npm-cli.js 文件损坏或丢失,就会出现 ENOENT。或者,问题可能是
npm install -g 在某些 Windows 配置上尝试使用 C:\Program Files\nodejs 作为全局安装目录,这可能需要提升的权限。让我检查一下脚本是否有处理权限问题的逻辑... 没有,脚本没有检查管理员权限或使用
sudo 等效命令。在 Windows 上,全局 npm 安装有时会失败,因为:- 默认全局目录是
%APPDATA%\npm,但在某些安装中可能是C:\Program Files\nodejs,这需要管理员权限才能写入。
实际上,查看现代 Node.js 安装,npm 全局包通常应该安装到
%APPDATA%\npm(用户目录),而不是 C:\Program Files\nodejs,后者是 Node 本身安装的位置。结论:问题很可能与 npm 配置、损坏的 npm 安装或全局安装路径的权限问题有关。最简单的解决步骤是:
- 清除 npm 缓存:
npm cache clean --force - 验证 npm 安装:
npm -v和node -v - 如果可能,尝试使用 npx 而不是全局安装:
npx clawdbot@latest - 或尝试先安装 pnpm(脚本支持),然后使用 pnpm 安装
- 检查
C:\Program Files\nodejs\node_modules\npm是否存在且未损坏
由于用户提供了脚本,但我无法修改他们本地运行的脚本,我应该为他们提供诊断和解决 ENOENT 错误的具体步骤。
ENOENT(Error NO ENTity)表示 npm 无法找到它试图执行的文件。从截图中截取的路径片段
"C:\Program Files\nodejs\node_mo 来看,npm 的模块路径似乎被截断或损坏了,或者 npm 正在尝试调用一个不存在的外部程序(如 Git,尽管错误类型不匹配)。根本原因分析:
- 路径解析错误:npm 的全局安装路径配置可能异常,导致尝试写入
C:\Program Files\nodejs目录(需要管理员权限)。 - npm 安装损坏:
C:\Program Files\nodejs\node_modules\npm目录可能损坏。 - 权限问题:尝试在没有管理员权限的情况下写入系统目录。
- 缓存损坏:npm 缓存损坏也可能导致 ENOENT。
解决方案建议:
- 使用 npx 避免全局安装(最简单):powershellCopy
npx clawdbot@latest - 修复 npm 路径:powershellCopy
npm config get prefix # 如果显示是 C:\Program Files\nodejs,则改为用户目录 npm config set prefix $env:APPDATA\npm # 确保该目录在 PATH 中 - 检查 Git 安装:从脚本逻辑看,如果 npm 安装失败并返回 ENOENT,可能是缺少 Git。虽然报错信息看起来像是在调用 node 相关的文件时出错,但也可能是包在安装过程中需要 Git。
- 手动安装步骤:如果自动脚本持续失败,建议手动执行
npm install -g clawdbot@latest并观察详细错误。 - 使用 Git 方式安装:如果 npm 方式持续失败,可以使用
-InstallMethod git参数切换到 Git 克隆安装方式。
让我为用户提供一个结构化的诊断和解决步骤。
这个
ENOENT 错误表示 npm 在尝试执行安装时找不到关键文件(通常是 npm 自身的模块或全局安装路径配置异常)。这是 Windows 上 Node.js 安装的常见问题。由于错误出现在脚本自动执行阶段,以下是几种绕过该问题的解决方案(按推荐顺序尝试):
方案 1:使用 npx 免安装(最快)
如果不想处理全局安装权限问题,可以直接用 npx 运行:
powershell
Copy
npx clawdbot@latest onboard如果这能工作,每次使用
clawdbot 时都改为使用 npx clawdbot@latest <命令>。方案 2:修复 npm 全局路径后安装
最可能的根本原因是 npm 试图写入
C:\Program Files\nodejs(需要管理员权限),而不是用户目录。步骤:
powershell
Copy
# 1. 检查当前 prefix(如果输出是 C:\Program Files\nodejs,那这就是问题)
npm config get prefix
# 2. 修改为当前用户目录(无需管理员权限)
npm config set prefix "$env:APPDATA\npm"
# 3. 确保该路径在环境变量中(PowerShell 临时添加)
$env:Path = "$env:Path;$env:APPDATA\npm"
# 4. 重新尝试安装
npm install -g clawdbot@latest方案 3:使用 Git 方式安装(绕过 npm 全局安装)
你的安装脚本支持从源码直接安装(使用 git + pnpm),这通常更稳定:
powershell
Copy
# 先确保有 git
winget install Git.Git
# 然后使用 git 方式运行安装脚本
& ([scriptblock]::Create((iwr -useb https://molt.bot/install.ps1))) -InstallMethod git这会克隆仓库到
~/clawdbot 并使用 pnpm 构建,避免 npm 的全局路径问题。方案 4:检查 npm 完整性(如果以上都失败)
如果
C:\Program Files\nodejs\node_modules\npm 目录损坏,会导致 ENOENT:powershell
Copy
# 验证 npm 自身是否正常
npm -v
node -p "require('fs').existsSync('C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js')"
# 如果不正常,建议重新下载 Node.js LTS 安装包覆盖安装
# https://nodejs.org/dist/v22.13.1/node-v22.13.1-x64.msi立即可行的诊断命令
在尝试修复前,建议你先在 PowerShell 中运行以下命令,我可以通过输出来定位具体原因:
powershell
Copy
Write-Host "Prefix: $(npm config get prefix)"; Write-Host "Cache: $(npm config get cache)"; npm config ls -l | findstr "prefix\|global"最推荐做法:先尝试 方案 2 修改 prefix,如果仍报错,直接使用 方案 3 的 Git 安装方式,这完全避开了 Windows 下 npm 全局安装的权限和路径问题。