3

I am trying to set up lint-staged following the instructions from the prettier documentation.
When I run npx mrm@2 lint-staged, I get the following error:

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

I followed the link from the error and changed the scripts section in package.json accordingly.

 "scripts": {
    "prepare": "cd .. && husky install laravel/.husky"
  }

I still get the same error when running npx mrm@2 lint-staged. What can I do to get lint-staged running?

My project structure:

project
│   .git    
└───laravel
    │   package.json
mgottsch
  • 559
  • 1
  • 3
  • 12
  • 1
    `cd ..` might be moving the cwd to a folder which is not in a git repo? – evolutionxbox Jan 28 '22 at 12:05
  • I run `npx mrm@2 lint-staged` inside the `laravel` folder and the `package.json` is also located there. So I think `cd ..` should move the cwd to `project`, which is the root of the git repo. Or am I missing something? – mgottsch Jan 28 '22 at 12:22
  • *Git* hooks always start in the root of the repository. *Husky* may or may not do something different, though judging from the link you included, it looks like "does not do something different" is correct and therefore `cd ..` would be wrong. – torek Jan 29 '22 at 05:08

1 Answers1

0

So I think cd .. should move the cwd to project, which is the root of the git repo.

Simply add pwd && cd .. && husky....
That way, you will know for sure from where you are starting from.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I do not receive any output other than the error. To check whether it is actually the prepare script what's crashing i added `touch /tmp/i_ran && cd.. (...)` and it seems prepare is not even running. – mgottsch Jan 31 '22 at 12:33
  • @MoritzGottschling OK, so the error is not from the execution of any husky command then. – VonC Jan 31 '22 at 13:53