It seems like there was an issue running npx husky add .husky/commit-msg 'npx --no-install commitlint --edit $1' because the command part was more than one word. A workaround I found was to split it up into two parts.
1 - Call npx husky add .husky/commit-msg
This created an empty/ default file in the right place with the following content:
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
undefined
2 - Then I just replaced undefined with npx --no-install commitlint --edit $1 and it works
This part of the commitlint docs helped me understand that doing it that way was okay
Hope this helps anyone else who encounters the same issue!
Answer from PMO1948 on Stack OverflowVideos
It seems like there was an issue running npx husky add .husky/commit-msg 'npx --no-install commitlint --edit $1' because the command part was more than one word. A workaround I found was to split it up into two parts.
1 - Call npx husky add .husky/commit-msg
This created an empty/ default file in the right place with the following content:
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
undefined
2 - Then I just replaced undefined with npx --no-install commitlint --edit $1 and it works
This part of the commitlint docs helped me understand that doing it that way was okay
Hope this helps anyone else who encounters the same issue!
You are using Windows. So, try this (it worked for me)
npx husky add .husky/commit-msg "npx --no-install commitlint --edit "$1""
with double quotes instead. Note that $1 also needs double quotes.
alexandreafa,
I got the same issue with yours, package.json file and .git directory are not at the same level. But I found a way to fix it, Step by step.
- Install commitlint (ref:https://github.com/conventional-changelog/commitlint)
# Install commitlint cli and conventional config
npm install --save-dev @commitlint/{config-conventional,cli}
# For Windows:
npm install --save-dev @commitlint/config-conventional @commitlint/cli
# Configure commitlint to use conventional config
echo "module.exports = {extends: ['@commitlint/config-conventional']}" > commitlint.config.js
# Add hook
cat <<EEE > .husky/commit-msg
#!/bin/sh
. "\$(dirname "\$0")/_/husky.sh"
npx --no -- commitlint --edit "\${1}"
EEE
chmod a+x .husky/commit-msg
- update the
commit-msg
CHANGE
npx --no -- commitlint --edit "\${1}
TO
cd nestedFolderRoot npx --no -- commitlint --edit "\${1}
fixed.
Now you could use git commit -m "type: xxxx" to commit it.
I had the same issue, got it fixed by replacing
cd ./frontend && npx commitlint --edit with "cd frontend && npm run commitlint ${1}"
and running command - npm set-script commitlint "commitlint --color --edit"
incase the package.json doesnt get updated ensure you have [email protected] else
execute - npm install -g [email protected]
also saw what you did with prepare config:
Incase if you have package.json and .git at different level of directory:
( If - when git directory at same level as package.json repository) ----------npx husky-init && npm install husky
(else if single sub_level) ----------npm set-script prepare "cd .. && husky install ${parent_repository_name}/.husky" then npm i
(else) ----------npm set-script prepare "cd ../.. && husky install ${parent_repository_name}/${sub_repositories_name}/.husky" then npm i
» npm install @commitlint/config-conventional