Different results with `npx husky init` and `npm run prepare`
Author: shardul-bCreated Feb 14, 2025Updated Feb 2, 2026
Troubleshoot
- [ x ] Before creating an issue, please check: https://typicode.github.io/husky/troubleshoot.html
Context
I have a monorepo like folder structure, but without a package.json in root folder.
root
| - node_project_1
| - node_project_2Based on the docs I went inside node_project_1 and executed npx husky init in terminal. This command simply generated a .husky directory and a pre-commit file.
My pre-commit hook didn't work.
Next I followed the "project not in git root directory" part and updated the prepare command to "prepare": "cd .. && husky node_project_1/.husky".
Post running npm run prepare I got a _ directory in .husky and pre-commit hook started working correctly.
This was observed on a MAC with node version: v22.11.0 and husky: ^9.1.7
Thank you!
Source: typicode/husky