question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'husky install' fails if '.git' directory does not exists

See original GitHub issue

I 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:closed
  • Created 3 years ago
  • Reactions:14
  • Comments:49 (5 by maintainers)

github_iconTop GitHub Comments

90reactions
LinnJScommented, Feb 27, 2021

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.

image

34reactions
samuelaj1commented, Jun 10, 2022

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found