我正在将nvm
与--no-use
标志一起使用,因为这导致我的终端启动速度非常慢🐌。这意味着我总是需要在新的终端选项卡上运行nvm use <NODE_VERSION>
才能使用node
或npm
。
我有一个使用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
标志当然会解决,但这不是一个选择,因为这样终端会在启动时变得非常慢。还有其他解决方法吗? 🙏
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