【问题标题】:WebStorm mocha test 'sh' is not recognized as an internal or external commandWebStorm mocha test 'sh' 未被识别为内部或外部命令
【发布时间】:2017-08-15 18:07:04
【问题描述】:

我正在尝试为我的 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 设置,但我不知道它是什么。有什么想法吗?

附:我在 Windows 上。

【问题讨论】:

    标签: windows bash exec sh webstorm


    【解决方案1】:

    对于那些在 Windows 上使用 phpStorm 并通过 Google 来这里的人

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

    还要在环境变量的 PATH 中添加 C:\Program Files\Git\bin

    【讨论】:

      【解决方案2】:

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

      打开设置/首选项对话框的终端页面,配置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

      【讨论】:

      • 试过了,还是不行。该页面说我应该能够在那之后运行 git 命令,但这也不起作用。我得到$ git statussh: git: command not found
      • 更新:此解决方案允许我从本地终端运行 sh 命令,但 javascript 代码仍然失败。
      • 你能从普通的 Git Bash 和 webstorm 终端运行一个实验和echo $PATH 吗?我怀疑它们可能不同
      • 它打印同样的东西。但是,当我执行exec('echo $PATH') 时,它只会打印$PATH。看起来被 Webstorm 生成的 shell 的环境设置不正确。
      • 如果它打印了 '$PATH' 你的引用实际上只是在防止变量扩展。没有设置路径会打印一个换行符。
      猜你喜欢
      • 2021-03-06
      • 2014-04-29
      • 1970-01-01
      • 1970-01-01
      • 2013-10-06
      • 2019-05-07
      • 2013-10-11
      • 2013-01-25
      • 2016-10-01
      相关资源
      最近更新 更多