Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix error 'not found husky-run' when committing new code?

Tags:

git

husky

When committing on a project that uses Husky, I get an error that says not found husky-run

I checked the package.json and it has husky as a dependency, and I can see the pre-commit hook configuration for Husky in the package.json. So I don't know what to do to fix this. Additionally, other members on my team can commit and husky works for them.

I also tried rm -rf node_modules && npm install and then committing again, but still, I get the same error.

Anyone else have ideas on how to fix this?

like image 541
frosty Avatar asked Feb 17 '21 17:02

frosty


People also ask

How do you ignore a husky pre-commit?

Use the --no-verify option to skip git commit hooks, e.g. git commit -m "commit message" --no-verify . When the --no-verify option is used, the pre-commit and commit-msg hooks are bypassed.

How do I disable my husky?

You can set HUSKY environment variable to 0 in your CI config file, to disable hooks installation. Alternatively, most Continuous Integration Servers set a CI environment variable. You can use it in your hooks to detect if it's running in a CI.

How do you skip a pre-commit?

Quick tip if you want to skip the pre-commit validations and quickly want to get a commit out there. To get your commit through without running that pre-commit hook, use the --no-verify option. Voila, without pre-commit hooks running!


Video Answer


1 Answers

To fix this there are two methods, depending on which version of Husky you are already on.

If you're using Husky v4 or lower, do the following:

rm -rf .git/hooks npm install 

For Husky v7 or greater, do the following:

# For NPM  npm install husky@7 --save-dev \       && npx husky-init \       && npm exec -- github:typicode/husky-4-to-7 --remove-v4-config  # For Yarn  yarn add husky@7 --dev \   && npx husky-init \   && npm exec -- github:typicode/husky-4-to-7 --remove-v4-config # or  yarn add husky@7 --dev \   && yarn dlx husky-init --yarn2 \   && npm exec -- github:typicode/husky-4-to-7 --remove-v4-config 

At this point you should be able to commit and have your hooks working again.

If anything goes wrong, please read the documentation for migration from 4 to 7.

like image 69
frosty Avatar answered Oct 06 '22 11:10

frosty