commitlint: Not working with husky (cygpath)

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

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 7
  • Comments: 15 (2 by maintainers)

Most upvoted comments

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

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.

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.

Nope, it’s a problem of the used git distribution. cygpath seems also be missing in github desktop.

The included bash sets MSYS env, which causes the npm shell wrapper to use cygpath.

It is actually a Husky problem. I had the issue with GitHub Desktop, not Visual Studio. Husky v1 works fine for example.

It’s a visual studio issue, in the included git version the cygpath.exe is missing.

https://developercommunity.visualstudio.com/t/Missing-cygpathexe-in-git/1393876