Lint-staged: Error: spawn git ENOENT in events.js:160

Created on 29 Aug 2017  Â·  13Comments  Â·  Source: okonet/lint-staged

version: 4.0.4

"scripts": {
      "precommit": "lint-staged",
},
"lint-staged": {
      "gitDir": "./path/to/packagejson/",
    "*.js": [
      "eslint --fix",
      "git add"
    ]
}
  • "git add" some files
  • "git commit" produce:
> husky > npm run -s precommit (node v6.10.3)
> 
> events.js:160
>       throw er; // Unhandled 'error' event
>       ^
> 
> Error: spawn git ENOENT
>     at exports._errnoException (util.js:1018:11)
>     at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32)
>     at onErrorNT (internal/child_process.js:367:16)
>     at _combinedTickCallback (internal/process/next_tick.js:80:11)
>     at process._tickCallback (internal/process/next_tick.js:104:9)
> 
> husky > pre-commit hook failed (add --no-verify to bypass)

No other node process on background.

Most helpful comment

Try to use the following config:

"lint-staged": {
  "gitDir": "./path/to/packagejson/",
  "linters" : {  
    "*.js": [
      "eslint --fix",
      "git add"
    ]
  }
}

All 13 comments

thanks for reporting this!
can you paste your package.json here as an additional information?

The config is malformed and missing linters property. Please refer to https://github.com/okonet/lint-staged#advanced-config-format

@okonet Thanks for responding - but linters property is optional no?
Here is the package.json:

{
  "name": "SomeName",
  "version": "0.1.0",
  "description": "Desc",
  "engines": {
    "npm": ">=3"
  },
  "scripts": {
    "precommit": "lint-staged",
    "preinstall": "node tools/nodeVersionCheck.js",
    "setup": "node tools/setup/setupMessage.js && npm install && node tools/setup/setup.js",
    "remove-demo": "babel-node tools/removeDemo.js",
    "start-message": "babel-node tools/startMessage.js",
    "prestart": "npm-run-all --parallel start-message remove-dist",
    "start": "npm-run-all --parallel test:watch open:src lint:watch",
    "open:src": "babel-node tools/srcServer.js",
    "open:dist": "babel-node tools/distServer.js",
    "lint": "esw webpack.config.* src tools --color --ext .js,.jsx",
    "lint:watch": "npm run lint -- --watch",
    "clean-dist": "npm run remove-dist && mkdir dist",
    "remove-dist": "rimraf dist'",
    "prebuild": "npm run lint && npm run test",
    "build": "babel-node tools/build.js",
    "test": "mocha tools/testSetup.js \"src/**/*.spec.js\" --reporter progress",
    "test:cover": "babel-node node_modules/isparta/bin/isparta cover --root src --report html node_modules/mocha/bin/_mocha -- --require ./tools/testSetup.js \"src/**/*.spec.js\" --reporter progress",
    "test:cover:travis": "babel-node node_modules/isparta/bin/isparta cover --root src --report lcovonly _mocha -- --require ./tools/testSetup.js \"src/**/*.spec.js\" && cat ./coverage/lcov.info | node_modules/coveralls/bin/coveralls.js",
    "test:watch": "npm run test -- --watch",
    "open:cover": "npm run test:cover && open coverage/index.html"
  },
  "lint-staged": {
    "gitDir": "./path/to/packagejson/",
    "*.js": [
      "eslint --fix",
      "git add"
    ]
  },
  "author": "",
  "license": "MIT",
  "dependencies": {
    "axios": "0.16.2",
    "bootstrap": "3.3.7",
    "bootstrap-sass": "3.3.7",
    "classnames": "2.2.5",
    "cropperjs": "1.0.0-rc.3",
    "draft-convert": "1.4.8",
    "draft-js": "0.10.1",
    "font-awesome": "4.7.0",
    "immutable": "3.8.1",
    "intl": "1.2.5",
    "moment": "2.18.1",
    "object-assign": "4.1.0",
    "prop-types": "15.5.10",
    "react": "15.5.4",
    "react-addons-css-transition-group": "15.3.2",
    "react-addons-shallow-compare": "15.6.0",
    "react-bootstrap": "0.31.1",
    "react-cropper": "0.12.0",
    "react-css-modules": "4.5.2",
    "react-dates": "12.2.4",
    "react-document-title": "2.0.3",
    "react-dom": "15.5.4",
    "react-fontawesome": "1.6.1",
    "react-intl": "2.3.0",
    "react-redux": "5.0.5",
    "react-redux-toastr": "4.4.6",
    "react-router": "3.0.5",
    "react-router-redux": "4.0.8",
    "react-simple-colorpicker": "1.4.1",
    "redux": "3.6.0",
    "redux-form": "7.0.0",
    "redux-thunk": "2.1.0",
    "uuid": "3.1.0"
  },
  "devDependencies": {
    "autoprefixer": "7.1.2",
    "babel-cli": "6.24.1",
    "babel-core": "6.25.0",
    "babel-eslint": "7.2.3",
    "babel-jest": "20.0.3",
    "babel-loader": "7.1.1",
    "babel-plugin-react-display-name": "2.0.0",
    "babel-plugin-react-intl": "2.3.1",
    "babel-plugin-syntax-dynamic-import": "6.18.0",
    "babel-plugin-transform-react-constant-elements": "6.23.0",
    "babel-plugin-transform-react-remove-prop-types": "0.4.6",
    "babel-polyfill": "6.23.0",
    "babel-preset-env": "1.6.0",
    "babel-preset-latest": "6.24.1",
    "babel-preset-react": "6.24.1",
    "babel-preset-react-hmre": "1.1.1",
    "babel-preset-stage-1": "6.24.1",
    "babel-register": "6.24.1",
    "bootstrap-loader": "2.1.0",
    "browser-sync": "2.18.12",
    "chai": "4.1.0",
    "chalk": "2.0.1",
    "connect-history-api-fallback": "1.3.0",
    "coveralls": "2.13.1",
    "cross-env": "5.0.1",
    "css-loader": "0.28.4",
    "enzyme": "2.9.1",
    "eslint": "4.2.0",
    "eslint-plugin-flowtype": "2.35.0",
    "eslint-plugin-import": "2.7.0",
    "eslint-plugin-jsx-a11y": "6.0.2",
    "eslint-plugin-react": "7.1.0",
    "eslint-watch": "3.1.2",
    "extract-text-webpack-plugin": "3.0.0",
    "file-loader": "0.11.2",
    "flow-bin": "0.50.0",
    "font-awesome-sass-loader": "2.0.1",
    "html-webpack-plugin": "2.29.0",
    "identity-obj-proxy": "3.0.0",
    "ignore-loader": "0.1.2",
    "isparta": "4.0.0",
    "jest": "20.0.4",
    "json-loader": "0.5.4",
    "lint-staged": "4.0.4",
    "mocha": "3.4.2",
    "mockdate": "2.0.1",
    "node-sass": "4.5.3",
    "npm-run-all": "4.0.2",
    "open": "0.0.5",
    "opn-cli": "3.1.0",
    "postcss-loader": "1.2.1",
    "prompt": "1.0.0",
    "prop-types": "15.5.10",
    "react-addons-test-utils": "15.6.0",
    "react-hot-loader": "3.0.0-beta.6",
    "react-test-renderer": "15.5.4",
    "redux-immutable-state-invariant": "2.0.0",
    "replace": "0.3.0",
    "resolve-url-loader": "2.1.0",
    "rimraf": "2.6.1",
    "sass-loader": "6.0.6",
    "sinon": "2.3.8",
    "sinon-chai": "2.12.0",
    "style-loader": "0.18.2",
    "url-loader": "0.5.9",
    "webpack": "3.3.0",
    "webpack-bundle-analyzer": "2.8.2",
    "webpack-combine-loaders": "2.0.3",
    "webpack-dev-middleware": "1.11.0",
    "webpack-dev-server": "^2.7.1",
    "webpack-hot-middleware": "2.18.2",
    "webpack-md5-hash": "0.0.5"
  },
  "keywords": [],
  "repository": {
    "type": "git",
    "url": ""
  }
}

I'm sorry but did you exactly write this line in your config?

"gitDir": "./path/to/packagejson/",

No, no, this is the path to my package.json.
Sorry for not being clear

On Tue, Aug 29, 2017, 9:05 PM Lufty Wiranda notifications@github.com
wrote:

I'm sorry but did you exactly write this line in your config?

"gitDir": "./path/to/packagejson/",`

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/okonet/lint-staged/issues/240#issuecomment-325746609,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAbQbyEO_xZmG-V_tcgGvkN_fmYEH_Omks5sdFL9gaJpZM4PF5IT
.

but linters property is optional no?

Not unless you use the advanced format i.e. if you have anything more than just linters, you have to defined them explicitly. In your case, you want to set gitDir so you _have_ to use advanced config.

I'll try to get config validation done soon since it is the most common source of issues.

Try to use the following config:

"lint-staged": {
  "gitDir": "./path/to/packagejson/",
  "linters" : {  
    "*.js": [
      "eslint --fix",
      "git add"
    ]
  }
}

Thanks for your answer - But still get the same the error.

I'm not sure but it looks like you pointing it to the wrong place. gitDir should be pointed to the root of your project I.e. Where the .git directory is.

Oh, So maybe I misunderstood the gitDir definition, checking

Yes, indeed I was setting the path from .git to package.json, while I was needed to set the path from package.json to .git folder.
Its was stupid mistake but maybe its worth validate the gitDir property and produce appropriate error message.
Sorry to bother you - I appreciate the support!

Glad you were able to get it sorted!

See also #141

Was this page helpful?
0 / 5 - 0 ratings