运行npm start及使用npx创建React应用时遇ENOENT错误求助
解决npm报错ENOENT(找不到bash.exe)
你遇到的是Windows系统下npm尝试调用C:\Windows\System32\bash.exe失败的ENOENT错误,错误详情如下:
npm ERR! code ENOENT npm ERR! syscall spawn C:\Windows\System32\bash.exe npm ERR! path E:\chatX npm ERR! errno -4058 npm ERR! enoent spawn C:\Windows\System32\bash.exe ENOENT npm ERR! enoent This is related to npm not being able to find a file. npm ERR! enoent npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\admin\AppData\Local\npm-cache\_logs\2023-03-17T19_49_37_928Z-debug-0.log
以下是几种可行的解决办法:
安装Git Bash并配置环境变量
- 下载安装Git for Windows(自带Git Bash),安装过程中务必勾选"Add Git to PATH"选项。
- 找到Git Bash的安装路径(默认是
C:\Program Files\Git\bin\bash.exe),将该路径添加到系统环境变量的PATH列表中。 - 重启你的命令行工具(CMD/PowerShell),再重新执行npm相关命令。
启用Windows Subsystem for Linux(WSL)
- 以管理员权限打开PowerShell,执行以下命令:
wsl --install - 安装完成后重启电脑,WSL会自动在
C:\Windows\System32路径下配置bash.exe。 - 重启后再次运行npm命令即可。
- 以管理员权限打开PowerShell,执行以下命令:
修改npm默认shell为CMD
如果不想安装额外工具,可以强制npm使用Windows自带的CMD作为脚本执行shell:
在命令行中执行:npm config set script-shell "cmd.exe"设置完成后重新运行你的npm脚本。
内容的提问来源于stack exchange,提问作者Srinja333
相关产品推荐
相关产品推荐

