0

I'm trying to run prettier before committing my changes using Husky + lint-staged, but it is not working. It does find the files, but it fails when it tries to apply "prettier --write"

Err: 'prettier' is not recognized as an internal or external command, operable program or batch file.

Prettier does work when running the command on terminal.

prettier version 2.8.8 husky version 8.0.3 lint-staged 13.2.2 react 18

  "scripts": {
    ...
    "precommit": "lint-staged",
    "prepare": "cd .. && husky install my-project/.husky"
  },
  "lint-staged": {
    "**/*.{ts,tsx}": [
      "prettier --write"
    ]
  },

package error

deiabasile
  • 37
  • 3

1 Answers1

0

Try:

"lint-staged": {
   "**/*.{ts,tsx}": [
       "npm run beautify"
   ]
}

When run via an npm script, NPM does some magic to ensure binaries in node_modules are available.

adsy
  • 8,531
  • 2
  • 20
  • 31