當我的 Mac 使用 Git 提交代碼時,它被 Husky 拒絕,我看到以下錯誤:
> git -c user.useConfigOnly=true commit --quiet --allow-empty-message --file -
.husky/_/husky.sh: line 23: sh: command not found
husky - pre-commit hook exited with code 127 (error)
終端或 VSCode 也會報告錯誤。
我怎樣才能克服這個錯誤?
uj5u.com熱心網友回復:
這是關于github.com/typicode/husky/husky.sh#L23
sh -e "$0" "$@"
確保 sh 在你的$PATH(通常/bin/sh)
將一個添加echo "prg='$0'"到您的.husky/_/husky.sh只是除錯并檢查它是否是未找到的“$0”(為空)
并檢查 PATH 問題,問題 912
我使用 VS Code 和 Husky v6。
$PATH我從專案的根目錄運行 echo 。
然后我將輸出復制到目錄中的pre-commit檔案中.husky。我的預提交檔案如下所示:
#!/bin/sh . "$(dirname "$0")/_/husky.sh" export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" npx lint-staged
正如OP所提到的,參考Husky/ Command not found,~/.huskyrc應該正確設定NVM:
# ~/.huskyrc
# This loads nvm.sh and sets the correct PATH before running hook
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
uj5u.com熱心網友回復:
我的檔案配置錯誤導致了這個問題,通過修改這個檔案來解決這個問題。 https://typicode.github.io/husky/#/?id=command-not-found
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/426897.html
