You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows下设置npm默认shell为bash后npm start报错:command not found

解决方案

问题原因

你配置的bash路径使用了Windows原生的反斜杠格式,导致npm生成临时启动脚本时输出的是Windows风格路径,但bash无法正确解析这种缺少路径分隔符的格式(比如C:Users***~1...会被bash当作相对路径处理)。

修复步骤

  1. 修正npm的script-shell配置
    两种可行的配置方式:

    • 推荐使用Git Bash的POSIX风格路径:
      npm config set script-shell "/c/Program Files/git/bin/bash.exe"
      
    • 或者转义Windows路径中的反斜杠:
      npm config set script-shell "C:\\Program Files\\git\\bin\\bash.exe"
      

    也可以直接编辑npm配置文件(如~/.npmrc),添加以下内容:

    script-shell=/c/Program Files/git/bin/bash.exe
    
  2. 验证配置有效性
    运行命令确认shell路径已正确设置:

    npm config get script-shell
    
  3. 重新测试npm start
    再次执行npm start,此时bash应该能正确识别临时脚本的路径。

额外排查方案

如果问题仍存在:

  • 检查Git Bash的实际安装路径,部分系统中Git的文件夹名称是大写的Git,路径应为C:\Program Files\Git\bin\bash.exe
  • 清理npm缓存后重试:
    npm cache clean --force
    

内容的提问来源于stack exchange,提问作者Tony

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.25 21:12:32