组合 commitizen + husky 时无法提交:nvm 与 "npm_config_prefix" 环境变量不兼容
Can't commit when combining commitizen + husky: nvm is not compatible with the "npm_config_prefix" environment variable
我有一个使用 commitizen 没有问题的项目。我已经决定将 husky 添加到 运行 precommit
钩子中。问题是当我 运行 npm run cm
命令时,我得到这个错误...
.....................
? Are there any breaking changes? No
? Does this change affect any open issues? No
nvm is not compatible with the "npm_config_prefix" environment variable: currently set to "/Users/aiglesias/.nvm/versions/node/v8.9.4"
Run `unset npm_config_prefix` to unset it.
.git/hooks/pre-commit: line 49: node: command not found
husky > npm run -s precommit (node )
env: node: No such file or directory
husky > pre-commit hook failed (add --no-verify to bypass)
/Users/aiglesias/Coding/react/react-basesupsub/node_modules/commitizen/dist/cli/strategies/git-cz.js:102
throw error;
^
Error: git exited with error code 1
at ChildProcess.<anonymous> (/Users/aiglesias/Coding/react/react-basesupsub/node_modules/commitizen/dist/git/commit.js:50:26)
at emitTwo (events.js:126:13)
at ChildProcess.emit (events.js:214:7)
at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! react-basesupsub@0.0.0-development cm: `git-cz`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the react-basesupsub@0.0.0-development cm script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/aiglesias/.npm/_logs/2018-02-03T08_22_42_663Z-debug.log
我删除了 prettier 并尝试只使用 husky 和基本的 npm run test
预提交挂钩,但出现相同的错误。显然,我看到了消息,但我不知道 运行ning unset npm_config_prefix
是否会在其他地方给我带来更大的问题。
已编辑:
- 我的环境中既没有设置
$NPM_CONFIG_PREFIX
也没有设置 $PREFIX
。
- 我试过
unset npm_config_prefix
,但结果相同。
发疯之后,显然是当前稳定版的husky问题。升级到新的 husky 0.15.0-rc.3
版本解决了这个问题。
以防万一你以后遇到这个问题,要升级你只需要...
npm i husky@next -D
转到 package json
并将你的钩子从 "script"
移动到新的 husky.hooks 部分,注意修改后的名称(来自 precommit
pre-commit
,例如)。就我而言...
之前:
"scripts": {
...
"precommit": "lint-staged"
}
之后:
"scripts": {
...
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
}
我有一个使用 commitizen 没有问题的项目。我已经决定将 husky 添加到 运行 precommit
钩子中。问题是当我 运行 npm run cm
命令时,我得到这个错误...
.....................
? Are there any breaking changes? No
? Does this change affect any open issues? No
nvm is not compatible with the "npm_config_prefix" environment variable: currently set to "/Users/aiglesias/.nvm/versions/node/v8.9.4"
Run `unset npm_config_prefix` to unset it.
.git/hooks/pre-commit: line 49: node: command not found
husky > npm run -s precommit (node )
env: node: No such file or directory
husky > pre-commit hook failed (add --no-verify to bypass)
/Users/aiglesias/Coding/react/react-basesupsub/node_modules/commitizen/dist/cli/strategies/git-cz.js:102
throw error;
^
Error: git exited with error code 1
at ChildProcess.<anonymous> (/Users/aiglesias/Coding/react/react-basesupsub/node_modules/commitizen/dist/git/commit.js:50:26)
at emitTwo (events.js:126:13)
at ChildProcess.emit (events.js:214:7)
at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! react-basesupsub@0.0.0-development cm: `git-cz`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the react-basesupsub@0.0.0-development cm script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/aiglesias/.npm/_logs/2018-02-03T08_22_42_663Z-debug.log
我删除了 prettier 并尝试只使用 husky 和基本的 npm run test
预提交挂钩,但出现相同的错误。显然,我看到了消息,但我不知道 运行ning unset npm_config_prefix
是否会在其他地方给我带来更大的问题。
已编辑:
- 我的环境中既没有设置
$NPM_CONFIG_PREFIX
也没有设置$PREFIX
。 - 我试过
unset npm_config_prefix
,但结果相同。
发疯之后,显然是当前稳定版的husky问题。升级到新的 husky 0.15.0-rc.3
版本解决了这个问题。
以防万一你以后遇到这个问题,要升级你只需要...
npm i husky@next -D
转到
package json
并将你的钩子从"script"
移动到新的 husky.hooks 部分,注意修改后的名称(来自precommit
pre-commit
,例如)。就我而言...之前:
"scripts": { ... "precommit": "lint-staged" }
之后:
"scripts": { ... }, "husky": { "hooks": { "pre-commit": "lint-staged" } }