Husky 9 no longer uses the husky add command
npx husky add .husky/pre-commit "npm test"Short answer
Husky 9 treats a hook as a plain file in .husky/. Create the file instead of running husky add, run husky init once to set up the prepare script, and replace husky install with husky. Git arguments are now $1, not HUSKY_GIT_PARAMS. Hooks that cannot find node in a Git app need a startup file.
Fix it fast
1Find out which cause you have
Check which Husky version is installed and what the prepare script runs. An old script line is the usual reason a copied tutorial no longer works.
npm ls husky grep -n "husky" package.json2Match what you see, then jump to its fix
- 1
The commands from a v8 guide, such as npx husky add .husky/pre-commit "npm test", do not create the hook.A tutorial still uses husky addFix - 2
husky install in package.json after an upgrade to v9.The prepare script still calls husky installFix - 3
A commit-msg hook written for an older Husky, for example commitlint -E HUSKY_GIT_PARAMS, stops working.A hook uses HUSKY_GIT_PARAMSFix - 4
Hooks pass in the terminal but fail when you commit from a Git app that was not started from a shell.Git GUI cannot find nodeFix
- 1
What does the error look like?
npx husky add .husky/pre-commit "npm test"husky installHUSKY_GIT_PARAMS
Cause 1 of 4
A tutorial still uses husky add
1Check
In the v8 flow the add command wrote the hook file. The v9 release notes show that adding a hook is just creating a file.
ls -la .husky/2Fix
Run the init command once, then write the hook yourself with an editor, a script or echo. The file name is the Git hook name.
npx husky init
echo "npm test" > .husky/pre-commit3Verify
Add exit 1 at the end of the hook, try a commit and confirm that Git blocks it. Remove the line afterwards.
echo "exit 1" >> .husky/pre-commit
git commit --allow-empty -m "testing pre-commit code"Confirmed by github.com
Cause 2 of 4
The prepare script still calls husky install
1Check
The v9 notes say husky install was removed, and husky does the same job.
grep -n "prepare" package.json2Fix
Change the prepare script to call husky. The init command does this for you.
// package.json
"scripts": { "prepare": "husky" }3Verify
Run the script, then make a test commit with a failing hook (exit 1) to see that Git runs it.
npm run prepareConfirmed by github.com
Cause 3 of 4
A hook uses HUSKY_GIT_PARAMS
1Check
v9 removed HUSKY_GIT_PARAMS. The migration guide says to use the Git parameters directly in the script.
grep -rn "HUSKY_GIT_PARAMS" .husky/ package.json2Fix
Replace the variable with $1 in the hook file, and call locally installed tools through your package manager.
# .husky/commit-msg
commitlint --edit $13Verify
Make a commit with a bad message and a good one.
git commit --allow-empty -m "bad message"Confirmed by typicode.github.io
Cause 4 of 4
Git GUI cannot find node
1Check
GUIs launched outside a terminal may not load version managers such as nvm, so node is missing from PATH.
command -v node2Fix
Husky reads ~/.config/husky/init.sh before each hook. Put the version manager's start-up lines there.
# ~/.config/husky/init.sh
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"3Verify
Commit once from the GUI.
git log -1 --statConfirmed by typicode.github.io
How do I stop it coming back?
- Read the hook file in .husky/ like any other script: it is the source of truth now.
- Set HUSKY=0 in CI where hooks are not wanted.
- Commit the .husky folder, and keep prepare in package.json so every clone installs hooks.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
husky prints .git can't be found and no hooks get installed
.git can't be found
Husky checks for a .git folder in the directory where its install script runs.
3 causes, each with a fixBack end
ng serve says it cannot determine the project or target
Cannot determine project for command.
The Angular CLI looked through angular.json for a project that defines the target you asked for (serve, build, test) and found none, or found several and could not pick one.
3 causes, each with a fixBack end
ng fails with Cannot find module @angular/cli/bin/ng
Cannot find module '@angular/cli/bin/ng'
The ng command is the entry point to the Angular CLI package.
2 causes, each with a fixBack end
Angular app shows 'Cannot GET /' when served by a Node.js server
Cannot GET /dashboard
Cannot GET / is Express saying no route or file matches the request.
3 causes, each with a fixBack end
ng serve cannot find the dev-server builder package
Could not find the implementation for builder @angular/build:dev-server
The builder named in angular.json (for example @angular-devkit/build-angular:dev-server) is looked up as an npm package starting from the workspace root.
3 causes, each with a fixBack end
Angular build says it cannot resolve '@angular/localize/init'
Can't resolve '@angular/localize/init' in '/usr/src/app/src'
The build imports @angular/localize, and that package is not in node_modules.
2 causes, each with a fix