I'm trying to set up automatic linting on commit for my company's project, and the best way I've seen to do so has been the husky
NPM package. I'm following instructions on setting up Husky
with eslint
, prettier
, and lint-staged
but I keep hitting on the same issue that I can't figure out how to resolve.
My problem is that my project is set up like so:
- Parent Directory
- .git
- Working Project Directory
- node_modules
- package.json
When i attempt to install husky, I get an error that I am missing the .git
file, however it's there, just one level up in the file structure!!
I have seen some things in other posts about using the following technique to fix it:
npx mrm lint-staged
This will fail, that’s expected
Then fix the npm prepare script
"prepare": "husky install" -> "prepare": "cd .. && husky install some-folder/.husky"
Then run
npm i
However it doesn't work for me.
I have also attempted to install husky in the parent directory
but it doesn't quite work and it makes the install process of our project more difficult
Does anyone have any suggestions?
EDIT: Here is the error message I get:
% npx husky-ini
t && npm install
Need to install the following packages:
husky-init
Ok to proceed? (y) y
husky-init updating package.json
setting prepare script to command "husky install"
/Users/me/.npm/_npx/1ab9c0f68ac2536e/node_modules/husky/lib/index.js:22
throw new Error(`.git can't be found (see ${url})`);
^
Error: .git can't be found (see https://typicode.github.io/husky/#/?id=custom-directory)
at install (/Users/me/.npm/_npx/1ab9c0f68ac2536e/node_modules/husky/lib/index.js:22:15)
at Object.<anonymous> (/Users/me/.npm/_npx/1ab9c0f68ac2536e/node_modules/husky-init/lib/bin.js:16:21)