Commitlint: Not working with husky (cygpath)

Created on 21 Apr 2020  Β·  11Comments  Β·  Source: conventional-changelog/commitlint

husky > commit-msg (node v13.11.0)
/c/Users/yahyaaba/Documents/GitHub/atom-ide-community/atom-ide-datatip/node_modules/.bin/commitlint: line 5: cygpath: command not found
internal/modules/cjs/loader.js:979
  throw err;
  ^

Error: Cannot find module 'C:\commitlint\cli.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:976:15)
    at Function.Module._load (internal/modules/cjs/loader.js:859:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
husky > commit-msg hook failed (add --no-verify to bypass)

My deps:

    "@commitlint/config-conventional": "^8.3.4",
    "commitlint": "^8.3.5",
    "husky": "^4.2.5"

using "@commitlint/cli": "^8.3.5", instead doesn't help.

husky > commit-msg (node v13.11.0)
sh: commitlint: command not found
husky > commit-msg hook failed (add --no-verify to bypass)

Affected packages

  • [ x] cli

Most helpful comment

Is theer a fix or workaround for this? I'm still getting a similar error

─ git commit -am "fix"
husky > pre-commit (node v12.18.3)
⚠ Some of your tasks use `git add` command. Please remove it from the config since all modifications made by tasks will be automatically added to the git commit index.

βœ” Preparing...
βœ” Running tasks...
βœ” Applying modifications...
βœ” Cleaning up... 
husky > commit-msg (node v12.18.3)
sh: commitlint: command not found <<<<<< broken here
husky > commit-msg hook failed (add --no-verify to bypass)

try:
cnpm install @commitlint/config-conventional @commitlint/cli -g

All 11 comments

I don't have a windows so I can't try to reproduce this.
I wonder were cygpath: command not found comes from. Googling it says it's a "cygwin"-command. Maybe that's the main issue? Could that be? Just a guess.

I'm using it in Sublime Merge, and am getting the same error as well:

husky > commit-msg (node v12.16.2)
/d/Programming/node_modules/.bin/commitlint: line 5: cygpath: command not found
internal/modules/cjs/loader.js:983
  throw err;
  ^

Error: Cannot find module 'D:\@commitlint\cli\lib\cli.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:980:15)
    at Function.Module._load (internal/modules/cjs/loader.js:862:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
    at internal/main/run_main_module.js:18:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
husky > commit-msg hook failed (add --no-verify to bypass)

It's fine if I npx commit in PowerShell though

I identified the issue for my case - I was relying on SublimeMerge's embedded Git. Once I configured it to use the system installed Git (i.e. Git for Windows), then the error went away.

@aminya You might wanna check if Atom is using an embedded Git as well, instead of your system's Git.

The error happens for me on both GitHub and Atom. But strangely, it doesn't happen with Tortoise Git.

@aminya I tried using GitHub Desktop v2.5.0, Windows 10, with the File > Options > shell set to Command Prompt. Not sure if this was your configuration as well, but I was unable to reproduce the error:
image

Very strange. It was working perfectly until now, and suddenly it stopped working.
Tried with GitExtensions (using external Git), VSC's terminal, and regular terminal.

$ git commit -m "chore: bump up dependencies"
husky > pre-commit (node v10.14.2)
i No staged files match any configured task.
husky > commit-msg (node v10.14.2)
sh: commitlint: command not found
husky > commit-msg hook failed (add --no-verify to bypass)

(Using an old Node because of project constraints.)

    "@commitlint/cli": "^9.1.2",
    "@commitlint/config-conventional": "^9.1.2",
    "husky": "^4.2.5",
    "lint-staged": "^10.2.13",
[...]
  "husky": {
    "hooks": {
      "pre-commit": "lint-staged",
      "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
    }
  },
  "lint-staged": {
    "*.scss": [
      "stylelint"
    ],
    "*.ts": [
      "tslint -c tslint.json"
    ],
    "src/**/*.ts": [
      "pretty-quick --staged --verbose --pattern 'src/**/*.ts'"
    ]
  },

[EDIT] It might be related to pretty-quick which was upgraded to 3.0.0 from 2.0.1.
It requires Node >= 10.13.0 but might fail with my 10.14 version…
The error persisted after I changed back to 2.0.1 and doing a new install.
I had to rm -rf node_modules and doing npm i again to get it to work again.

Conclusion: it might be a bug with Husky, failing to chain to next task if one (silently) fails.

Definitely this is a bug. Either in Husky or Git Hooks or commit lint.

One thing I noticed with this is that it sometimes works if you run the shell as administrator! Not sure why this is related. That's why TortoiseGit worked for me. GitHub desktop, however, opens the shell in a regular mode, not admin.

Because of all of these issues, I gave up using Commitlint with Husky altogether. I use a GitHub Action for this:
https://github.com/wagoid/commitlint-github-action
The action also helps to keep the devDependencies cleaner.

There is a solution in this issue:
https://github.com/typicode/husky/issues/673#issuecomment-674292969
or this StackOverflow question:
https://stackoverflow.com/questions/61196309/husky-4-x-not-working-with-visual-studio-git

We should use npx in the hooks

Is theer a fix or workaround for this? I'm still getting a similar error

─ git commit -am "fix"
husky > pre-commit (node v12.18.3)
⚠ Some of your tasks use `git add` command. Please remove it from the config since all modifications made by tasks will be automatically added to the git commit index.

βœ” Preparing...
βœ” Running tasks...
βœ” Applying modifications...
βœ” Cleaning up... 
husky > commit-msg (node v12.18.3)
sh: commitlint: command not found <<<<<< broken here
husky > commit-msg hook failed (add --no-verify to bypass)

Is theer a fix or workaround for this? I'm still getting a similar error

─ git commit -am "fix"
husky > pre-commit (node v12.18.3)
⚠ Some of your tasks use `git add` command. Please remove it from the config since all modifications made by tasks will be automatically added to the git commit index.

βœ” Preparing...
βœ” Running tasks...
βœ” Applying modifications...
βœ” Cleaning up... 
husky > commit-msg (node v12.18.3)
sh: commitlint: command not found <<<<<< broken here
husky > commit-msg hook failed (add --no-verify to bypass)

try:
cnpm install @commitlint/config-conventional @commitlint/cli -g

Is theer a fix or workaround for this? I'm still getting a similar error

─ git commit -am "fix"
husky > pre-commit (node v12.18.3)
⚠ Some of your tasks use `git add` command. Please remove it from the config since all modifications made by tasks will be automatically added to the git commit index.

βœ” Preparing...
βœ” Running tasks...
βœ” Applying modifications...
βœ” Cleaning up... 
husky > commit-msg (node v12.18.3)
sh: commitlint: command not found <<<<<< broken here
husky > commit-msg hook failed (add --no-verify to bypass)

try:
cnpm install @commitlint/config-conventional @commitlint/cli -g

It works!

Was this page helpful?
0 / 5 - 0 ratings