How to migrate from husky 8 to 9


This post goes over how to migrate from husky 8 to 9.

husky install

Upgrade husky to 9 in package.json:

npm install --save-dev husky@9

After running install, you might see the warning:

install command is deprecated

The fix is to replace postinstall with prepare:

-    "postinstall": "husky install",
+    "prepare": "husky",

pinst

If you’re using pinst, remove it from your scripts and devDependencies:

-    "postpublish": "pinst --enable",
-    "prepublishOnly": "pinst --disable && npm run build",
+    "prepublishOnly": "npm run build",
-    "pinst": "3.0.0",

Then run npm install so hasInstallScript is removed from your package-lock.json:

npm install

.husky

Remove .husky/.gitignore if it’s present:

rm .husky/.gitignore

Remove the shebang and husky script at the top of your hooks:

-#!/usr/bin/env sh
-. "$(dirname -- "$0")/_/husky.sh"

Commit your changes and verify your hooks are still working:

git add . && git commit -v

Check out husky’s v9 release notes for more information.



Please support this site and join our Discord!