lint-staged command is not found
when I use package.json below, the output is 'lint-staged command is not found'
{
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
...
}
when I use the npm command like this, It work
{
"scripts": {
"lint": "lint-staged"
},
"husky": {
"hooks": {
"pre-commit": "npm run lint"
}
},
...
}
How can I fix it up?
OS: windows terminal: git bash git version: 2.17
$ HUSKY_DEBUG=1 git commit
PS D:\Users\fangyy001\Desktop\project\veb-third-web\cmbwp> git commit
husky > pre-commit (node v12.13.0)
'lint-staged' 不是内部或外部命令,也不是可运行的程序
Hi fayfang,
lint-stagedis another package. Runnpm install lint-staged --save-devto install it.
yeah, but I am confused that why the cmd in ./node_module/.bin can not be used when git commit. not only the lint-staged ,but also all the cmd in ./node_module/.bin can not be used.
Can you show the error message?
(In case you're using macOS or a GNU/Linux distribution, force an English message via LC_ALL=C ./node_modules/.bin/husky resp. with the git command).
It may be worth testing with Husky v4.
As the reason why npm run lint works but not calling lint-staged directly, I suspect it's because npm run modifies PATH to include node_modules/.bin. On the other side, when hook commands are run PATH isn't modified.
On the other side, when hook commands are run
PATHisn't modified.
Is this an intentional change in behavior from v3? I'm running into the same issue.
.husky/pre-commit: line 4: lint-staged: command not found
I get now this error message with husky v5.0.4 and lint-staged v10.5.1.
Update: Adding yarn lint-staged to the pre-commit husky file fixed it.
Update: Adding yarn lint-staged to the pre-commit husky file fixed it.
That's the right fix, for husky v5 and v4, locally installed commands need to be run via the package manager.
So yarn lint-staged or npx --no-install lint-staged will work.
Alternatively, this will work too:
// .husky/pre-commit (v5) or .huskyrc (v4)
npm run pre-commit
// package.json
{
"scripts": {
"pre-commit": "lint-staged"
}
}
If the husky hook is not being called, try to install version 4: npm install husky@4 --save-dev
To follow @typicode's message:
I suspect it's because npm run modifies PATH to include node_modules/.bin. On the other side, when hook commands are run PATH isn't modified.
If you change your .husky/pre-commit to include this path, it works with husky@latest:
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
node_modules/.bin/lint-staged
Adding npx lint-staged to the pre-commit husky file fixed it for me.
Adding
npx lint-stagedto the pre-commit husky file fixed it for me.
Also this worked for me.
If you are also desperately trying to fix ".husky/pre-commit: line 4: lint-staged: command not found", add "npx lint-staged" to your pre-commit file. Read more about the solution here: https://storksnestblog.wordpress.com/2023/01/11/fixing-husky-lint-staged-command-not-found-error/
Adding
npx lint-stagedto the pre-commit husky file fixed it for me.
I should've read your comment earlier :D