美文网首页
解决mac下sourcetree中运行husky命令提示 npm

解决mac下sourcetree中运行husky命令提示 npm

作者: 小枫学幽默 | 来源:发表于2021-08-10 11:32 被阅读0次

背景:

在项目中加入了 husky, 并在gitpre-commit钩子中加入eslint校验,在命令行中使用git commit -m "fix: eslint"时,pre-commit钩子中的 shell文件正常执行,但我使用sourceTree做同样的操作时,却提示:npm: command not found(还有同学会提示(npx : command not found))

pre-commit钩子中代码如下

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npm run lint:staged

package.json中的脚本为

"scripts": {
    "lint:staged": "npx lint-staged"
 },

解决方案

pre-commit钩子中加入PATH变量解析

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
# 加入下面这行
PATH="/usr/local/bin:$PATH"
npm run lint:staged

相关文章

网友评论

      本文标题:解决mac下sourcetree中运行husky命令提示 npm

      本文链接:https://www.haomeiwen.com/subject/rpdxbltx.html