Skip to content

fix: husky commit-msg commitlint not working in Windows #3557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 of 4 tasks
wisnupramoedya opened this issue Mar 5, 2023 · 2 comments
Closed
1 of 4 tasks

fix: husky commit-msg commitlint not working in Windows #3557

wisnupramoedya opened this issue Mar 5, 2023 · 2 comments
Labels

Comments

@wisnupramoedya
Copy link

wisnupramoedya commented Mar 5, 2023

Expected Behavior

I am actually quite new to husky and commitlint. I've been searching numerous issues related to this bug in this repo. However, I couldn't find a solution.

In my commit-msg file

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx --no -- commitlint --edit $1

At first, on my commit-msg, I try to remove the npx --no -- commitlint --edit $1, It showed this log when I committed with git commit -m "build: add configuration eslint prettier and husky"

✔ Preparing lint-staged...
✔ Hiding unstaged changes to partially staged files...
✔ Running tasks for staged files...
✔ Applying modifications from tasks...
✔ Restoring unstaged changes to partially staged files...
✔ Cleaning up temporary files...

But when I appended that line, my commit got this error.

✔ Preparing lint-staged...
✔ Hiding unstaged changes to partially staged files...
✔ Running tasks for staged files...
✔ Applying modifications from tasks...
✔ Restoring unstaged changes to partially staged files...
✔ Cleaning up temporary files...
npm ERR! canceled

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\ASUS\AppData\Local\npm-cache\_logs\2023-03-05T14_55_41_633Z-debug-0.log
husky - commit-msg hook exited with code 1 (error)

Current Behavior

Adding the npx --no -- commitlint --edit $1, I've got this error.

✔ Preparing lint-staged...
✔ Hiding unstaged changes to partially staged files...
✔ Running tasks for staged files...
✔ Applying modifications from tasks...
✔ Restoring unstaged changes to partially staged files...
✔ Cleaning up temporary files...
npm ERR! canceled

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\ASUS\AppData\Local\npm-cache\_logs\2023-03-05T15_20_57_145Z-debug-0.log
husky - commit-msg hook exited with code 1 (error)

On the log, it said. I have no clue what I should do.

0 verbose cli C:\Program Files\nodejs\node.exe C:\Users\ASUS\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js
1 info using [email protected]
2 info using [email protected]
3 timing npm:load:whichnode Completed in 0ms
4 timing config:load:defaults Completed in 3ms
5 timing config:load:file:C:\Users\ASUS\AppData\Roaming\npm\node_modules\npm\npmrc Completed in 6ms
6 timing config:load:builtin Completed in 6ms
7 timing config:load:cli Completed in 5ms
8 timing config:load:env Completed in 1ms
9 timing config:load:file:E:\Sekolah\Tugas Kuliah\Semester 7\TA\myits-puspresnas-nextjs\.npmrc Completed in 0ms
10 timing config:load:project Completed in 9ms
11 timing config:load:file:C:\Users\ASUS\.npmrc Completed in 0ms
12 timing config:load:user Completed in 1ms
13 timing config:load:file:C:\Users\ASUS\AppData\Roaming\npm\etc\npmrc Completed in 0ms
14 timing config:load:global Completed in 0ms
15 timing config:load:validate Completed in 0ms
16 timing config:load:credentials Completed in 2ms
17 timing config:load:setEnvs Completed in 3ms
18 timing config:load Completed in 31ms
19 timing npm:load:configload Completed in 31ms
20 timing npm:load:mkdirpcache Completed in 1ms
21 timing npm:load:mkdirplogs Completed in 0ms
22 verbose title npm exec commitlint --edit .git/COMMIT_EDITMSG
23 verbose argv "exec" "--yes" "false" "--" "commitlint" "--edit" ".git/COMMIT_EDITMSG"
24 timing npm:load:setTitle Completed in 2ms
25 timing config:load:flatten Completed in 5ms
26 timing npm:load:display Completed in 7ms
27 verbose logfile logs-max:10 dir:C:\Users\ASUS\AppData\Local\npm-cache\_logs
28 verbose logfile C:\Users\ASUS\AppData\Local\npm-cache\_logs\2023-03-05T15_20_57_145Z-debug-0.log
29 timing npm:load:logFile Completed in 14ms
30 timing npm:load:timers Completed in 0ms
31 timing npm:load:configScope Completed in 0ms
32 timing npm:load Completed in 61ms
33 silly logfile start cleaning logs, removing 2 files
34 timing arborist:ctor Completed in 2ms
35 silly logfile done cleaning log files
36 http fetch GET 200 https://registry.npmjs.org/commitlint 1106ms (cache revalidated)
37 timing arborist:ctor Completed in 0ms
38 timing command:exec Completed in 1152ms
39 verbose stack Error: canceled
39 verbose stack     at exec (C:\Users\ASUS\AppData\Roaming\npm\node_modules\npm\node_modules\libnpmexec\lib\index.js:177:17)
39 verbose stack     at async module.exports (C:\Users\ASUS\AppData\Roaming\npm\node_modules\npm\lib\cli.js:78:5)
40 verbose cwd E:\Sekolah\Tugas Kuliah\Semester 7\TA\myits-puspresnas-nextjs
41 verbose Windows_NT 10.0.22621
42 verbose node v18.14.0
43 verbose npm  v8.12.1
44 error canceled
45 verbose exit 1
46 timing npm Completed in 1449ms
47 verbose code 1
48 error A complete log of this run can be found in:
48 error     C:\Users\ASUS\AppData\Local\npm-cache\_logs\2023-03-05T15_20_57_145Z-debug-0.log

I use Yarn v1, hence #2990 comment is not working also.

I've tried this solution #3555 comment, It is also got the same cancelled error.

When I run npx directly in my terminal.

  1. echo "build: add configuration eslint prettier and husky" | npx commitlint // give no output, I think it is working
  2. echo "with husky" | npx commitlint // give problems output as I intended

Affected packages

  • cli
  • core
  • prompt
  • config-angular

Possible Solution

No response

Steps to Reproduce

  1. I add in package.json
...
"scripts": {
    ...
    "prepare": "cd .. && husky install src/.husky"
},
...
"devDependencies": {
    "@commitlint/cli": "^17.4.4",
    "@commitlint/config-conventional": "^17.4.4",
    "husky": "^8.0.3",
    ...
}
...
  1. I started yarn install
  2. I added this to commit-msg
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx --no -- commitlint --edit $1
  1. Create the config file commitlint.config.js and add this in it:
module.exports = {
  extends: ['@commitlint/config-conventional'],
  rules: {
    'type-enum': [
      2,
      'always',
      [
        'feat',
        'fix',
        'docs',
        'build',
        'chore',
        'style',
        'refactor',
        'ci',
        'test',
        'perf',
        'revert',
        'vercel',
      ],
    ],
  },
};

  1. I run git commit -m "build: add configuration eslint prettier and husky" and it produced the earlier issues

Context

I'm trying to use another rule and ensure the same type of commit message in my project. I use yarn version 1 and run this program on Windows.

commitlint --version

@commitlint/cli@^17.4.4

git --version

v2.34.1.windows.1

node --version

v18.14.0

@wisnupramoedya
Copy link
Author

I am sorry, this problem was coming from me.

I had this structure of the directory:

.git
frontend/
- husky/
  - commit-msg
  - pre-commit
  - post-merge
- package.json

Because the .git folder was outside of my husky directory, I required to add cd .. && husky install frontend/.husky in prepare. Hence, based on this Husky Custom Directory, I should add another cd frontend in my hooks.

Sorry for the inconvenience. I will close this issue.

@miesmile
Copy link

I am sorry, this problem was coming from me.

I had this structure of the directory:

.git
frontend/
- husky/
  - commit-msg
  - pre-commit
  - post-merge
- package.json

Because the .git folder was outside of my husky directory, I required to add cd .. && husky install frontend/.husky in prepare. Hence, based on this Husky Custom Directory, I should add another cd frontend in my hooks.

Sorry for the inconvenience. I will close this issue.

Hello, I would like to ask where cd frontend sentence was added, because I originally had a line cd *** in the commit-msg file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants