[英]Node not reconized with Git hook on windows
我正在使用赫斯基(7.0.0)在现有电子项目(在 Windows 上)上设置预提交挂钩。 要安装赫斯基,我遵循了文档(此处),并且使用以下两个文件正确创建了 .husky 文件夹:husky.sh
#!/bin/sh
if [ -z "$husky_skip_init" ]; then
debug () {
if [ "$HUSKY_DEBUG" = "1" ]; then
echo "husky (debug) - $1"
fi
}
readonly hook_name="$(basename "$0")"
debug "starting $hook_name..."
if [ "$HUSKY" = "0" ]; then
debug "HUSKY env variable is set to 0, skipping hook"
exit 0
fi
if [ -f ~/.huskyrc ]; then
debug "sourcing ~/.huskyrc"
. ~/.huskyrc
fi
export readonly husky_skip_init=1
sh -e "$0" "$@"
exitCode="$?"
if [ $exitCode != 0 ]; then
echo "husky - $hook_name hook exited with code $exitCode (error)"
fi
exit $exitCode
fi
并预先提交:
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npm test
所以现在在提交之前应该运行测试脚本(测试脚本只包含运行jest,即“test”:“jest”)。 但是当我(从终端)运行 git commit 时,它会失败并显示以下输出: console output 。 错误消息指出 git 无法找到节点,但它看起来很奇怪的是输出的前两行,这表明 jest 实际运行。 我正在使用节点 18.0.0(通过 nvm-windows 管理)和 npm 7.24.2(这两个在windows 终端和git bash中都得到了确认)。 节点的路径已经在我的 $PATH 环境变量中。 如果我可以添加任何细节,请告诉我
我发现了我的问题,我的环境变量列表中有一个双引号,它使以下所有路径无效(其中有 nodejs 路径)。 为了理解这件事,我通过 git bash 手动运行了命令并列出了 PATH 环境变量。 无论如何,我仍然无法理解,如果我在 git bash 中运行npm -v
它会显示正确的节点版本,但尝试运行其他命令会导致错误
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.