kimi update fails to detect npm-global install source on Windows Git Bash (EINVAL in execFile)
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 70/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- typescript
- Domain
- cli
Research direction
Start in apps/kimi-code/src/cli/update/source.ts and read detectInstallSource around line 103, focusing on the npm prefix lookup and its catch path. Reproduce the npm.cmd EINVAL case in Windows Git Bash, then verify that the fallback recognizes npm-global package paths while leaving unrelated layouts unsupported.
Written by the indexing model from the issue text.
Description
问题描述
在 Windows 11 上通过 Git Bash 运行 kimi update 时,无法检测到 npm 全局安装来源,始终显示:
Detected install source: unsupported package manager or layout.
To update manually, run: npm install -g @moonshot-ai/kimi-code@x.x.x
即使 kimi-code 已通过 npm install -g 安装,detectInstallSource() 仍然返回 "unsupported"。
根因
源文件: apps/kimi-code/src/cli/update/source.ts
detectInstallSource 函数(约第 103 行)调用:
execFileText(npmCommand(platform), ["prefix", "-g"])
在 platform === "win32" 时,npmCommand 返回 "npm.cmd"。当 Node.js 进程由 Git Bash / MSYS2 环境启动时,child_process.execFile("npm.cmd", ...) 会抛出 EINVAL 错误(spawn 同样失败)。
catch 块直接返回 "unsupported",导致 canAutoInstall 返回 false,进入手动更新提示分支。
复现环境
- OS: Windows 11
- Shell: Git Bash (MSYS2)
- Node.js: v24.18.0 (via fnm)
- npm: 全局 prefix 为
%USERPROFILE%\.npm-global
验证
execFile("npm.cmd", ["prefix", "-g"]) → EINVAL
spawn("npm.cmd", ["prefix", "-g"]) → EINVAL
execFile("npm.cmd", ["prefix", "-g"], {shell:true}) → 正常工作
修复建议
在 catch 块中添加 fallback 启发式检测——当 npm prefix -g 因平台兼容性失败时,通过包路径模式判断是否属于 npm 全局安装:
} catch {
// Fallback: when npm prefix detection fails (e.g. EINVAL on Git Bash),
// check if package path matches a typical npm global node_modules layout
const normalized = normalizeForHeuristic(packageRoot);
const npmNodeModulesSeg = `/node_modules/${NPM_PACKAGE_NAME}`;
const npmLibSeg = `/lib${npmNodeModulesSeg}`;
if (normalized.endsWith(npmNodeModulesSeg.toLowerCase()) ||
normalized.endsWith(npmLibSeg.toLowerCase())) {
return "npm-global";
}
return "unsupported";
}
npm 全局安装的包路径始终以 <prefix>/node_modules/@moonshot-ai/kimi-code 结尾,这个启发式检测无需运行 npm 命令即可完成判断。
- Dominant language
- TypeScript
- Stars
- 7.5k
- Forks
- 1.2k
- Avg merge
- 11h 41m
- Merged PRs (30d)
- 345
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from MoonshotAI/kimi-code
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
MoonshotAI/kimi-code#3947 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
MoonshotAI/kimi-code#3836 · 2 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
MoonshotAI/kimi-code#3790 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
MoonshotAI/kimi-code#3755 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
MoonshotAI/kimi-code#3627 ·
All issues in MoonshotAI/kimi-code
Similar issues
-
calcite-components needs triage refactor
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Esri/calcite-design-system#15203 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 91/100
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 95/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Automattic/studio#4908 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100