2

我有一个项目使用 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 testprecommit 钩子,但出现了同样的错误。显然,我看到了消息,但我不知道跑步是否unset npm_config_prefix会在其他地方给我带来更大的问题。

编辑:

  • 在我的环境中既没有$NPM_CONFIG_PREFIX也没有设置。$PREFIX
  • 我试过unset npm_config_prefix了,但结果相同。
4

1 回答 1

3

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

以防万一您将来遇到此问题,升级您只需要...

  1. npm i husky@next -D
  2. 转到package json并将您的钩子"script"从新的 husky.hooks 部分移动,注意修改后的名称(例如 from precommitto pre-commit)。在我的情况下...

    前:

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

    后:

    "scripts": {
        ...
    },
    "husky": {
        "hooks": {
            "pre-commit": "lint-staged"
        }
    }
    
于 2018-02-04T07:51:30.480 回答