Can't commit when combining commitizen + husky: nvm is not compatible with the "npm_config_prefix" environment variable

时间:2018-02-03 09:04:44

标签: git npm nvm git-husky commitizen

I have a project that was using commitizen without problems. I've decided to add husky to run precommit hooks with prettier. The problem is that when I run the npm run cm command, I get this error...

.....................
? 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

I've removed prettier and try just husky and a basic npm run test precommit hook, with the same error. Obviously, I see the message, but I don't know if running unset npm_config_prefix can cause me bigger problems in other places.

EDITED:

  • Neither $NPM_CONFIG_PREFIX nor $PREFIX are set in my environment.
  • I've tried unset npm_config_prefix, but with the same results.

1 个答案:

答案 0 :(得分:1)

疯狂之后,显然是当前稳定版哈士奇的问题。升级到新的husky 0.15.0-rc.3版本解决了这个问题。

如果您将来遇到这个问题,升级只需要...

  1. npm i husky@next -D
  2. 转到package json并将您的摘要从"script"移至新的husky.hooks部分,注意修改后的名称(从precommitpre-commit , 例如)。就我而言......

    在:

    "scripts": {
        ...
        "precommit": "lint-staged"
    }
    

    在:

    "scripts": {
        ...
    },
    "husky": {
        "hooks": {
            "pre-commit": "lint-staged"
        }
    }