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

运行任意npx命令均触发ENOENT错误,请求解决

npx 执行命令报错(syscall spawn bash ENOENT)解决方法

问题复现

执行任意npx命令均报错,例如运行:

npx create-expo-app myApp

报错输出:

npm ERR! code ENOENT
npm ERR! syscall spawn bash
npm ERR! path C:\Users\Name\Documents\Programming\ReactNative
npm ERR! errno -4058
npm ERR! enoent spawn bash ENOENT
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

已尝试清除npm缓存,问题未解决。

解决步骤

  • 确认bash环境是否存在并配置
    Windows系统默认无bash环境,需安装Git Bash或WSL。若已安装,检查bash的执行路径是否添加到系统PATH环境变量中。
  • 强制npm使用cmd作为脚本shell
    执行以下命令修改npm配置:
    npm config set script-shell "cmd.exe"
    
    若需使用bash,指定其完整路径(以Git Bash为例):
    npm config set script-shell "C:\\Program Files\\Git\\bin\\bash.exe"
    
  • 验证配置是否生效
    运行命令查看当前设置的shell:
    npm config get script-shell
    
  • 检查项目路径合法性
    避免路径包含空格、非英文字符或过长,可将项目移至更简洁的路径,如C:\ReactNative\myApp。
  • 重装Node.js/npm
    若以上方法无效,卸载当前Node.js,重新下载官方稳定版安装,确保安装时勾选"Add to PATH"选项。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.24 11:55:04