'husky install' fails if '.git' directory does not exists
See original GitHub issueI have a postinstall
script in a NPM package:
"postinstall": "is-ci || husky install",
If I download the repository using Github UI (Code -> Download ZIP), after extracting it, executing npm install
raises Error: .git can't be found
:
postinstall error
> simple-icons-font@4.9.0 postinstall /.../simple-icons-font-develop
> is-ci || husky install
/.../simple-icons-font-develop/node_modules/husky/lib/commands/install.js:20
throw new Error(".git can't be found");
^
Error: .git can't be found
at Object.install (/.../simple-icons-font-develop/node_modules/husky/lib/commands/install.js:20:15)
at Object.<anonymous> (/.../simple-icons-font-develop/node_modules/husky/lib/bin.js:43:19)
I can prevent the error doing something like this:
"postinstall": "node -e \"if(require('fs').existsSync('.git')){process.exit(1)}\" || is-ci || husky install",
But it seems a bit hacky. What would be the recommended way to solve this?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:14
- Comments:49 (5 by maintainers)
Top Results From Across the Web
How to fix error 'not found husky-run' when committing new ...
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:...
Read more >Husky - Git hooks
Another case you may be in is if your package.json file and .git directory are not at the same level. For example, project/.git...
Read more >How to Fix the “fatal: not a git repository” Error - ContainIQ
Check that you correctly created the repo. If the directory doesn't contain a .git repo, use git init to properly initialize the repo...
Read more >Git Hooks | Atlassian Git Tutorial
All Git hooks are ordinary scripts that Git executes when certain events ... problems is to store your hooks in the actual project...
Read more >FAQ - Emulsify Design System
.git can't be found ... Are you getting this error? ... If so, remove the script "prepare": "husky install", from your package.json, and...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I am having this same issue when trying to install husky on a repo where I have multiple projects and the .git file is up a directory. Are there configuration options for this use case? I have two projects with node modules nested inside one git repo for the sanity CMS and the Gatsby FE.
The case you may be in is if your package.json file and .git directory are not at the same level. For example, project/.git and project/front/package.json.
By design, husky install must be run in the same directory as .git, but you can change directory during prepare script and pass a subdirectory:
Change script in package.json to this: // package.json { “scripts”: { “prepare”: “cd … && husky install front/.husky” } }
Then do npm install to fix it