Husky command not found

1.1k views Asked by At

I am using husky with yarn:4.0.1 workspace.

my pre-commit file looks like this:

#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

cd ./frontend && yarn test:linter:staged

The root package.json

{
  "name": "@my-workspace/test",
  "version": "0.0.1",
  "licence": "MIT",
  "private": true,
  "workspaces": [
    "frontend",
  ],
  "scripts": {
    "lint": "eslint --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
    "prepare": "husky install"
  },
  "devDependencies": {
    "@typescript-eslint/eslint-plugin": "^5.59.0",
    "@typescript-eslint/parser": "^5.59.0",
    "eslint": "^8.38.0",
    "eslint-config-prettier": "9.0.0",
    "eslint-plugin-prettier": "5.0.0",
    "eslint-plugin-react": "^7.33.2",
    "eslint-plugin-react-hooks": "^4.6.0",
    "eslint-plugin-react-refresh": "^0.3.4",
    "husky": "^8.0.0",
    "lint-staged": "^15.0.2",
    "prettier": "3.0.3",
    "typescript": "^5.0.2"
  },
  "lint-staged": {
    "*.{js,jsx,ts,tsx}": "eslint --fix --max-warnings 0 --ignore-path .gitignore --ignore-pattern '!next-env.d.ts'",
    "*.{js,jsx,ts,tsx,md,html,css,json}": "prettier --write"
  },
  "packageManager": "[email protected]"
}

The package.json in frontend

 "scripts": {
    "test:linter:staged": "lint-staged"
}

Everything seems to be working with older version of yarn. Since I have migrated to yarn:4.0.1.

I am getting following error during git commit

command not found: lint-staged
husky - pre-commit hook exited with code 127 (error)
husky - command not found in PATH=/opt/homebrew/opt/git/libexec/git-core:/Users/<USER_NAME>/.nvm/versions/node/v20.5.1/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin

The pre-commit hook file runs from bash, it runs without any issue.

Any idea what could be wrong here? Thanks in advance.

1

There are 1 answers

8
Shivo'ham On

in .husky folder in that one file named with pre-commit exists please add "npx lint-staged"

in your case this might be like this cd ./frontend && yarn lint-staged