fix(install): run npm from Windows paths with spaces - #426
Merged
Merged
Conversation
Quote the npm.cmd path before cmd.exe runs install steps, and query the npm global prefix through the same shell so Node no longer rejects the .cmd file with EINVAL. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
x-lixu
approved these changes
Sep 17, 2026
x-lixu
left a comment
Collaborator
There was a problem hiding this comment.
感谢修复 Windows 默认 Node 安装路径含空格时的一键安装问题,并补充真实 npm.cmd 回归测试。已同步最新 main;Windows Node 22/24、其他平台 CI、发布检查和移动端构建均通过,审查通过。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
变更说明
现象:Windows 上 Node.js 安装在含空格的目录(官方安装包默认的
C:\Program Files\nodejs)时,qwenaudio install <后台>与桌面版“安装”按钮的 npm 步骤立即失败:原因:
findExecutable('npm.cmd')返回完整路径C:\Program Files\nodejs\npm.cmd,runStep在 Windows 上以shell: true启动它。Node 只把命令与参数用空格拼接后交给cmd.exe /d /s /c,未加引号的路径在第一个空格处被截断。同一文件里安装后查询 npm 全局前缀的spawnSync(npmCommand, ['config', 'get', 'prefix'])没有经过 shell,Node 会以EINVAL拒绝直接启动.cmd,于是始终回退到%USERPROFILE%\AppData\Roaming\npm,自定义 npm prefix 时装好的命令不会进入 PATH。修复:仅在 Windows 且命令路径含空白、尚未加引号时为其加上双引号;前缀查询与安装步骤一致,经 shell 执行同一个带引号的命令。其他平台、无空格路径和
powershell.exe脚本步骤的行为不变。验证
本机 Windows 11,Node 24.17.0 / npm 11.13.0(与 CI 同为 Node 24 主版本)。
新增回归测试
runs npm.cmd from a Windows directory containing spaces:在临时目录的Program Files\nodejs下放置一个假的npm.cmd,经真实spawn走完整个installBackend('opencode'),并断言安装参数与 npm 前缀进入 PATH。非 Windows 平台跳过。修复前(未改
install.mjs):修复后:
node --test server/test/backend-install.test.mjs(26 通过)npm test(2366 项,2347 通过,19 跳过,0 失败)npm run lintnpm run build兼容性与安全
cmd.exe的命令路径引号,参数与 PATH 处理不变,不引入新的 shell 调用路径;前缀查询从“必定 EINVAL”变为正常执行npm config get prefix。无网络、权限或持久化影响。回滚:还原本 PR 即恢复原行为。🤖 Generated with Claude Code