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 Overflow
🌐
Theodorus Clarence
theodorusclarence.com › shorts › husky-commitlint-prettier
Husky, Commitlint, and Prettier Configuration | theodorusclarence.com
Checking the commit message following the conventional commits, it will fail to commit if the commit message is not following the rule. Writing prettier changes before each commit. This is done to prevent developers that did not have prettier installed in their machine. ... It will initialize all of the needed files including a sample pre-commit hook. ... module.exports = { extends: ['@commitlint/config-conventional'], rules: { // TODO Add Scope Enum Here // 'scope-enum': [2, 'always', ['yourscope', 'yourscope']], 'type-enum': [ 2, 'always', [ 'feat', 'fix', 'docs', 'chore', 'style', 'refactor', 'ci', 'test', 'revert', 'perf', 'vercel', ], ], }, };
🌐
Commitlint
commitlint.js.org › guides › local-setup.html
Guide: Local setup | commitlint
npm install --save-dev husky # husky@v9 npx husky init # husky@v8 or lower npx husky install # Add commit message linting to commit-msg hook echo "npx --no -- commitlint --edit \$1" > .husky/commit-msg
🌐
DEV Community
dev.to › mahmudulhsn › install-husky-in-your-project-for-proper-commit-lint-with-pre-commit-hooks-25b2
Install Husky in your project for proper commit lint with pre-commit hooks - DEV Community
May 10, 2025 - First of all, we need to install Husky. So let's start by installing Husky. To install Husky Run the following command. ... Next, create a file in your git root directory named .commitlintrc.json and add the following configuration: { "extends": ["@commitlint/config-conventional"] }
🌐
GitHub
github.com › conventional-changelog › commitlint
GitHub - conventional-changelog/commitlint: 📓 Lint commit messages
Common types according to commitlint-config-conventional (based on the Angular convention) can be: build · chore · ci · docs · feat · fix · perf · refactor · revert · style · test · These can be modified by your own configuration. Why Use Conventional Commits? "The perks of committing with conventions" (Talk slides) Local setup - Lint messages on commit with husky ·
Starred by 18.5K users
Forked by 965 users
Languages   TypeScript 92.1% | JavaScript 7.9%
🌐
Medium
medium.com › @shinjithkanhangad › git-good-automating-commit-message-standards-with-husky-and-commitlint-bac659f967d3
Git Good: Automating Commit Message Standards with Husky and Commitlint | by Shinjith P R | Medium
March 21, 2026 - Install @commitlint/cli and [@commitlint/config-conventional](https://github.com/conventional-changelog/commitlint/tree/master/@commitlint/config-conventional) as dev dependencies.
🌐
Michael Liendo
michaelliendo.com › en › notes › how-to-configure-husky
How to configure husky with conventional commits? Using Prettier and ESLint | Notes of Michael Liendo
December 14, 2023 - { "extends": ["@commitlint/config-conventional"] } ... Then we add the new configuration. For this we execute this command · npx husky add .husky/commit-msg 'npx commitlint --edit $1'
🌐
DEV Community
dev.to › fedtti › how-to-use-semantic-versioning-and-conventional-commits-with-husky-1g6i
How to Use Semantic Versioning and Conventional Commits With Husky - DEV Community
January 7, 2026 - mv .husky/pre-commit .husky/commit-msg echo "npx --no -- commitlint --edit $1" > .husky/commit-msg echo "export default { extends: ['@commitlint/config-conventional'] };" > commitlint.config.ts
Find elsewhere
🌐
Medium
kishannirghin.medium.com › how-to-set-up-conventional-commits-with-commitlint-and-husky-in-may-2021-f1fee7f6a1ee
How to set up Conventional Commits with Commitlint and Husky in may 2022 | by Kishan Nirghin | Medium
April 23, 2022 - Configure commitlint to use conventional commits echo "module.exports = {extends: ['@commitlint/config-conventional']};" > commitlint.config.js# Step 4. Install Husky (v7) npm install --save-dev husky # Step 5. Enable Husky # (NOTE: this will also add a "npm test" pre-commit hook) npx husky-init && npm install# Step 5.1 (Optionally) Delete the pre-commit hook rm .husky/pre-commit# Step 6.
🌐
Medium
medium.com › @thecreativerio › an-easy-configure-husky-and-commitlint-in-your-project-48d25f2a3f63
How to configure Husky and Commitlint in your project | by Mostafa | Medium
January 27, 2024 - Create a “commit-msg” file inside the “.husky” directory containing a command for running Commitlint: ... Based on our conventions we need to add a subject and type in our commit message. Let’s try one more time with a proper commit message: ... As you can see our changes were committed successfully. For the last part, we can also add a “pre-push” file in our .husky directory to run our build command right before pushing changes to the remote repository. ... We Successfully configured our hooks for Git commits using Husky and defined conventions and rules for better commit messages.
🌐
Zenn
zenn.dev › wakamsha › articles › about-conventional-commits
Conventional Commits: Basics and Supporting Technologies (commitlint + husky)
July 22, 2024 - Next, run the following command in the root directory of the repository to create the husky configuration file. ... When the command is successful, a .husky directory is created in the root directory. . +├── .husky/ +│ └── _/ └── package.json
Top answer
1 of 2
1

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.

2 of 2
0

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
npmjs.com › package › @commitlint › config-conventional
@commitlint/config-conventional - npm
6 days ago - Start using @commitlint/config-conventional in your project by running `npm i @commitlint/config-conventional`. There are 1376 other projects in the npm registry using @commitlin...
      » npm install @commitlint/config-conventional
    
Published   Apr 30, 2026
Version   20.5.3
🌐
Rxtsel
rxtsel.dev › en › blog › how-to-install-husky-commitlint-and-lint-staged-in-your-projects-a-step-by-step-guide
Blog · How to Install Husky, Commitlint, and lint-staged in Your Projects: A Step-by-Step Guide
February 7, 2024 - (Conventional Commits). lint-staged allows you to run linters on staged files before committing them. In this step-by-step guide, you’ll learn how to install and configure Husky, Commitlint and lint-staged in your projects.
🌐
DEV Community
dev.to › saiful7778 › improve-your-developer-lifecycle-with-husky-lint-staged-and-commitlint-3mj7
✨ Improve Your Developer Lifecycle with Husky, lint-staged, and commitlint - DEV Community
April 30, 2025 - { "extends": ["@commitlint/config-conventional"], "rules": { "type-enum": [ 2, "always", [ "ci", "chore", "docs", "feat", "fix", "perf", "refactor", "revert", "style", "assets", "test" ] ] } } ✅ This enforces commit types like feat, fix, docs, chore, etc. 🔴 Invalid: updated code ✅ Valid: feat: add login screen ... pnpm dlx husky install pnpm pkg set scripts.prepare="husky install" git add .