lint-staged: Error: fatal: Not a git repository
When trying to use lint-staged
and husky
in a project where the actual node.js project is a child directory of the git repo (as shown below):
project
└─ node-app
└─ package.json
I get the following error:
:; git commit
> husky - npm run -s precommit
Error: fatal: Not a git repository: '.git'
at ChildProcess.<anonymous> (/home/tri/project/node-app/node_modules/staged-git-files/index.js:85:19)
at emitTwo (events.js:106:13)
at ChildProcess.emit (events.js:191:7)
at maybeClose (internal/child_process.js:886:16)
at Socket.<anonymous> (internal/child_process.js:342:11)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at Pipe._handle.close [as _onclose] (net.js:501:12)
/home/tri/project/node-app/node_modules/lint-staged/src/index.js:44
files.forEach((file) => {
^
TypeError: Cannot read property 'forEach' of undefined
at sgf (/home/tri/project/node-app/node_modules/lint-staged/src/index.js:44:18)
at /home/tri/project/node-app/node_modules/staged-git-files/index.js:13:13
at /home/tri/project/node-app/node_modules/staged-git-files/index.js:38:13
at ChildProcess.<anonymous> (/home/tri/project/node-app/node_modules/staged-git-files/index.js:88:9)
at emitTwo (events.js:106:13)
at ChildProcess.emit (events.js:191:7)
at maybeClose (internal/child_process.js:886:16)
at Socket.<anonymous> (internal/child_process.js:342:11)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
When running npm run precommit
, I see a lot of these errors
:; npm run precommit
> node-app@1.0.0 precommit /home/tri/project/node-app
> lint-staged
❯ Running tasks for *.js
✖ prettier --single-quote --no-bracket-spacing --jsx-bracket-same-line --write
→ /home/tri/prooject/node-app/node-app/Link.react.js
git add
🚫 prettier --single-quote --no-bracket-spacing --jsx-bracket-same-line --write found some errors. Please fix them and try committing again.
Unable to read file:
Error: ENOENT: no such file or directory, open ''
Unable to read file: /home/tri/project/node-app/node-app/test/nightwatch/user.js
Error: ENOENT: no such file or directory, open '/home/tri/project/node-app/node-app/test/nightwatch/user.js'
Unable to read file: /home/tri/project/node-app/node-app/test/nightwatch/universalSearch.js
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 3
- Comments: 23
That’s why I encourage people to read the README when something isn’t working 😃
@maxime1992 You have to insert gitDir as property of lint-staged. like this.
Did you see https://github.com/okonet/lint-staged#working-from-a-subdirectory? What’s your config?
@sudo-suhas looks like the precommit passed. It was the postcommit that threw the error. I checked my .git folder, and the hooks are installed correctly. Below is my --debug output
@MJ111 this won’t work. You need to use advanced config with
linters
key. See READMEAh, I think I put that
gitDir
config as sibling tolint-staged
, not as a property of. My bad. Thanks for your help.