WebStorm摩卡测试' sh'不被视为内部或外部命令

时间:2017-08-15 18:07:04

标签: windows bash exec sh webstorm

我试图为运行以下行的node.js代码运行mocha测试:

exec(`sh ${scriptFile}`);

当我使用npm test从命令行(Git Bash)运行它时,它会通过。但是,当我从WebStorm运行它时,我收到以下错误:

'sh' is not recognized as an internal or external command,
operable program or batch file.

我觉得我可能错过了一些WebStorm设置,但我无法弄清楚它是什么。有什么想法吗?

P.S。我在Windows上。

2 个答案:

答案 0 :(得分:1)

Git Bash实现了一个模拟bash的* nix-esque shell,它可以解析你的命令。 Webstorm似乎试图在powershell或cmd中执行命令,这些命令不支持sh语法。

  

打开“设置/首选项”对话框的“终端”页面,然后按如下所示配置Shell路径字段:

     

"[path to the git installation]\bin\sh.exe" -login -i

这可能是"C:\Program Files\Git\bin\sh.exe" -login -i

来源:https://www.jetbrains.com/help/webstorm/2017.1/working-with-embedded-local-terminal.html

答案 1 :(得分:0)

对于那些在Windows上使用phpStorm并通过Google访问的人

在您的计算机上安装Git。转到Settings/Terminal并将shell path设置为C:\Program Files\Git\bin\sh.exe

还在环境变量中将C:\Program Files\Git\bin添加到PATH中。