I followed this example https://github.com/okonet/lint-staged#installation-and-setup
Have this in my package.json
"scripts": {
"pre-commit": "lint-staged"
},
and added this to my .lintstagedrc file
{
"*.css": "stylelint",
"*.scss": "stylelint --syntax=scss"
}
Latest OSX, Node version v6.10.0 and npm version 3.10.10
I had stylelint installed already and my stylelint works fine if I run via my grunt task. grunt stylelint
I made a change to my existing .scss file but don't get anything in CLI when I add files to staging and commit. Things just work like there is no lint-staged.
Edited
I followed this article https://medium.com/@okonetchnikov/make-linting-great-again-f3890e1ad6b8
// package.json
...
"scripts" {
"lint-staged": "lint-staged",
"stylelint-staged": "stylelint --syntax scss"
},
"lint-staged": {
"*.js": "eslint",
"*.scss": "stylelint-staged"
},
"pre-commit": "lint-staged"
...
and it worked but I get this warning too after linting errors
pre-commit:
pre-commit: We've failed to pass the specified git pre-commit hooks as the `lint-staged`
pre-commit: hook returned an exit code (1). If you're feeling adventurous you can
pre-commit: skip the git pre-commit hooks by adding the following flags to your commit:
pre-commit:
pre-commit: git commit -n (or --no-verify)
pre-commit:
pre-commit: This is ill-advised since the commit is broken.
pre-commit:
This warning is a part of pre-commit. You can try using husky instead (this is the recommended way now BTW). See README.
husky was not working that is what i m trying to explain at first place
@okonet Do we need to use husky and pre-commit both?
I uninstalled pre-commit and installed husky and getting this error
❯ git commit -m "feat(grunt): test"
> husky - npm run -s precommit
/Users/jitendravyas/app-v3/node_modules/lint-staged/src/index.js:6
const path = require('path')
^^^^^
SyntaxError: Use of const in strict mode.
at exports.runInThisContext (vm.js:73:16)
at Module._compile (module.js:443:25)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/Users/jitendravyas/app-v3/node_modules/lint-staged/index.js:2:1)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
> husky - pre-commit hook failed (add --no-verify to bypass)
> husky - to debug, use 'npm run precommit'
No, just choose one. pre-commit don't have uninstall scripts so you have to clean it up before installing husky probably.
Hmm, the error you're seeing seem to be in my code. Checking.
Not sure what's going on but I'd recommend cleaning up the .git/hooks directory — remove all actually hooks (without sample), rm -rf node_modules and do a new npm install.
I ran npm uninstall pre-commit to uninstall pre-commit
I ran rm -rf node_modules and npm install and getting this error upon git commit
❯ git commit -m "feat(grunt): test"
.git/hooks/pre-commit: line 2: ./node_modules/pre-commit/hook: No such file or directory
I think I can't remove all hooks because some other hooks were already there, were added by someone else before.
@okonet
A part of my package.json and stylelint, husky, lint-staged are already installed and .stylelintrc in root.
Now I'm stucked here
"scripts": {
"precommit": "lint-staged",
"postinstall": "cp git-hooks/* .git/hooks/ && chmod -R +x .git/hooks;",
"setup": "npm install -g grunt-cli; npm install -g bower; grunt requirejs:editor-inject; grunt sass:dev;",
"release-patch": "git checkout master && npm version patch && git push origin master --tags;",
"release-minor": "git checkout master && npm version minor && git push origin master --tags;",
"release-major": "git checkout master && npm version major && git push origin master --tags;"
},
"lint-staged": {"*.scss": ["stylelint --syntax scss"]},
Error on commit
❯ git commit -m "feat(grunt): test"
.git/hooks/pre-commit: line 2: ./node_modules/pre-commit/hook: No such file or directory
My git hooks directory

Above error is gone now after deleting .git/hooks/pre-commit file but stylelint linting not working I think now.

lint-staged is my branch-name here
I ran rm -rf node_modules and npm install again. after deleting .git/hooks/pre-commit file and setup everything again from here https://github.com/okonet/lint-staged#installation-and-setup
Now I'm back to this error again https://github.com/okonet/lint-staged/issues/165#issuecomment-301003092
Hi, @okonet are you checking that error or there could be other problem in my setup?
You're probably overwriting the pre-commit with this command:
"postinstall": "cp git-hooks/* .git/hooks/ && chmod -R +x .git/hooks;",
I removed the line from my package.json file
"postinstall": "cp git-hooks/* .git/hooks/ && chmod -R +x .git/hooks;",
and tried to commit a change. I get this in CLI
❯ git commit -m "feat(grunt): testtttttt"
> husky - npm run -s precommit
> husky - pre-commit hook failed (add --no-verify to bypass)
> husky - to debug, use 'npm run precommit'
Did you clean up the hooks dir and reinstall husky (by running npm install) after removing this line? I'm sorry you're going through this by I'm not sure how your team is managing git hooks.
You should probably contact the person who made this.
Did you try npm run precommit without the hook? Did it work?
Strangely, I am experiencing the same error. I removed the node_modules folder and pre-commit hook and then reinstalled via npm install which tells me I shall not pass although running npm run pre-commit passes by itself.
After a brief moment of clarity and looking at index.js, I realized I didn't have "lint-staged": "lint-staged" in my package.json which silently fails index.js:228for me. I apologize for the false alarm in my case.
Can this be closed please?
Leaving this here for other people that may run into the same issue:
I was running into the same issue
const pkg = require('./package.json')
^^^^^
SyntaxError: Use of const in strict mode.
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:945:3
Fix for me was to define a .nvmrc in my project
6.9.1
Removing and installing node_modules didn't fix my issue.
I removed whole project with rm -rf project-name and cloned again from the repository.
Then I have run npm i
Now it runs nice and neat.
in may case I just executed npm ci two times. The first just failed. And the second worked. And then the error was gone.
Happening the same with me too on windows machines. On the machines which have node v 10, it works fine. But those which have v 6, it doesn't work at all without showing any warning or errors. Not sure if the issue is with husky or prettier. But I'd bet on the issue is with lint-staged. I believe at least the read me should be updated to add the required node version. Here are the relevant parts of package.json
"scripts": {
"lint": "tslint \"resources/**/*.ts\""
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{js,ts,css,json,md}": [
"prettier --write",
"git add"
],
"*.{ts}": [
"npm run lint",
"eslint --fix",
"git add"
]
}
```
Same with me nothing happens
"scripts": {
"lint": "eslint **/*.{ts,tsx}",
"check-commit": "lint-staged"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{ts,tsx,css,json,md}": [
"prettier --write",
"git add"
],
"*.{ts,tsx}": [
"eslint --fix",
"git add"
]
}
i ran npm ci because I couldn't get lint-staged to work either. On re-install i saw a message in terminal:
husky > Setting up git hooks
Husky requires Git >= 2.13.2, please update Git
husky > Failed to install
So i ran git --version. I am on 2.9. So I updated git to 2.23 and ran npm ci again with a successful install.
now when I try to commit files my lint-staged hook runs and I see errors as expected.
Most helpful comment
I ran
rm -rf node_modulesandnpm installagain. after deleting.git/hooks/pre-commitfile and setup everything again from here https://github.com/okonet/lint-staged#installation-and-setupNow I'm back to this error again https://github.com/okonet/lint-staged/issues/165#issuecomment-301003092