-1
xxx-MacBook-Pro:client xxx$ npx mrm@2 lint-staged 
npx: installed 239 in 8.29s
Running lint-staged...
/Users/xxx/.npm/_npx/34378/lib/node_modules/mrm/bin/mrm.js:56
        throw err;
        ^

Error: .git can't be found (see https://typicode.github.io/husky/#/?id=custom-directory)
    at Object.install (/Users/xxx/.npm/_npx/34378/lib/node_modules/mrm/node_modules/husky/lib/index.js:20:15)
    at task (/Users/xxx/.npm/_npx/34378/lib/node_modules/mrm/node_modules/mrm-task-lint-staged/index.js:214:8)
    at /Users/xxx/.npm/_npx/34378/lib/node_modules/mrm/src/index.js:170:20

I got the error while trying to install Pre-commit Hook using lint-staged

Environment

  • npm : 6.14.17
  • node: 14.19.2
Mia.Zhang
  • 31
  • 6

1 Answers1

3

Fixed:

  • npx mrm@2 lint-staged

    Failed

  • Fix the npm prepare script
    "prepare": "cd .. && husky install client/.husky"

  • run npm i then

  • Added pre-commit manually

     #!/bin/sh  
    
     "$(dirname "$0")/_/husky.sh"
    
     cd client && npx lint-staged
    
    
  • run npm i again

Reason: package.json file and .git directory are not at the same level.

My code structure:

client
server
.gitignore

Mia.Zhang
  • 31
  • 6
  • That does the trick `package.json file and .git directory are not at the same level.` – a p Mar 09 '23 at 08:36