[在WebStorm和SourceTree中使用NVM时出现Git Hooks错误

问题描述 投票:4回答:1

我正在将nvm--no-use标志一起使用,因为这导致我的终端启动速度非常慢🐌。这意味着我总是需要在新的终端选项卡上运行nvm use <NODE_VERSION>才能使用nodenpm

我有一个使用ghooks配置了一些Git挂钩的项目,因此,每次我移到另一个分支或提交某些东西时,WebStorm和SourceTree都会收到不同类型的错误,所有这些都指出node无法被发现。这些是其中的一些:

SourceTree checkout

git -c diff.mnemonicprefix=false -c core.quotepath=false -c 
credential.helper=sourcetree checkout BRANCH
Switched to branch 'BRANCH'
M   ...
M   ...
...
env: node: No such file or directory
Completed with errors, see above

WebStorm commit

Commit failed with error
0 files committed, 3 files failed to commit: COMMIT_MESSAGE env: node: No such file or directory

[在WebStorm中,我认为手动设置要使用的node版本(在Preferences > Languages & Frameworks > Node.js and NPM > Node interpreter下可以解决此问题,但是没有。

我正在使用WebStorm 2016.1.3, Build #WS-145.1616

删除--no-use标志当然会解决,但这不是一个选择,因为这样终端会在启动时变得非常慢。还有其他解决方法吗? 🙏

node.js git webstorm githooks nvm
1个回答
1
投票

Git钩子是从非交互式shell调用节点,因此它没有使用您在安装nvm之后可能在.bashrc文件中设置的shell环境。

尝试添加:. $HOME/.nvm/nvm.sh到您的.git/hooks/pre-commit文件中>

最后看起来应该类似于:

#!/bin/bash
. $HOME/.nvm/nvm.sh
./node_modules/pre-commit/hook
RESULT=$?
[ $RESULT -ne 0 ] && exit 1
exit 0
© www.soinside.com 2019 - 2024. All rights reserved.