While working with Git and committing code, you might encounter this error:
husky - pre-commit hook exited with code 127 (error)
This error is very common when using Husky for Git hooks.
In this post, we’ll understand:
- What this error means
- Why it happens
- How to fix it step-by-step
- Temporary and permanent solutions
What is Husky?
Husky is a tool that helps you run scripts before Git actions like:
commitpush
For example:
- Running ESLint before commit
- Preventing bad code from being committed
The Error
husky - pre-commit hook exited with code 127 (error)
What Does Error Code 127 Mean?
Error code 127 means: “Command not found”
👉 In simple terms:
Husky is trying to run a command, but that command does not exist or cannot be found.
Why This Error Happens
This error usually occurs due to one of the following reasons:
1️⃣ Missing Dependencies
The command inside your pre-commit hook (like eslint, lint-staged) is not installed.
2️⃣ Incorrect Path
The script is not able to locate the command.
3️⃣ Node Modules Not Installed
You forgot to run:
npm install
4️⃣ Husky Not Installed Properly
Husky setup might be broken or incomplete.
5️⃣ Shell Environment Issues
Sometimes Git hooks don’t have access to your system PATH.
Quick Temporary Fix
If you want to skip the error and commit anyway:
git commit -m "your message" --no-verify
👉 This bypasses Husky hooks.
⚠️ Use this only as a temporary fix.
Above solution will also work for the following error too.
husky – pre-commit script failed(code 127)
Permanent Fix (Step-by-Step)
🔹 Step 1: Install Dependencies
npm install
🔹 Step 2: Check Husky Installation
npx husky install
🔹 Step 3: Verify Pre-Commit Hook
Open:
.husky/pre-commit
Make sure it contains valid commands like:
npx lint-staged
🔹 Step 4: Install Missing Tools
If you are using lint-staged:
npm install lint-staged --save-dev
🔹 Step 5: Use npx Instead of Direct Commands
❌ Wrong:
eslint .
✅ Correct:
npx eslint .
👉 This ensures the command runs from local dependencies.
🔹 Step 6: Reinstall Husky (If Needed)
rm -rf node_modules
rm -rf .huskynpm install
npx husky install
Real-World Scenario
You clone a project and try to commit:
git commit -m "initial commit"
💥 Error appears because:
- Dependencies are not installed
👉 Fix:
npm install
Common Mistakes
❌ Not running npm install
❌ Using global packages instead of local
❌ Incorrect Husky setup
❌ Missing lint-staged
Best Practice
- Always install dependencies before working
- Use
npxfor commands - Keep Husky properly configured
Final Summary
- Error 127 = Command not found
- Happens due to missing dependencies or wrong setup
- Use
--no-verifyfor temporary fix - Fix permanently by installing and configuring tools properly
💡 Facing more errors like this? Subscribe to get simple fixes, real-world debugging tips, and developer-friendly explanations. Happy Coding!

