10

Husky钩子在SourceTree中报错:.husky/pre-commit: Line 4 npm: command not found

 2 years ago
source link: https://xmanyou.com/sourcetree-husky-npm-command-not-found/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
1 November 2021 / husky

Husky钩子在SourceTree中报错:.husky/pre-commit: Line 4 npm: command not found

使用husky作为git钩子,在precommit回调中添加以下命令:

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run prettier:src
npm run lint

在命令行中可以正常commit,并正确触发钩子,但是,在SourceTree中,却报错了:

.husky/pre-commit: Line 4 npm: command not found

sourcetree-husky-npm-command-not-found-01

错误描述告诉我们,这是因为SourceTree找不到husky钩子中需要使用的命令。

解决方法
找到所需命令所在路径,然后添加到~/.huskyrc文件中。

找到npm所在路径的方法

$ where npm
/usr/local/bin/npm

需要注意的是,该文件默认是没有的,可以手动创建文件并添加以下配置:

export PATH="/usr/local/bin/:$PATH"

也可以用以下命令自动创建文件并添加路径:

echo 'export PATH="/usr/local/bin/:$PATH"' >> ~/.huskyrc

阿斌

Read more posts by this author.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK