pre-commit Failed : an unexpected error. spawn UNKNOWN -- Jhipster project

Viewed 93

I got an error while trying to commit !

  • node : v16.16.0
  • generator-jhipster : 6.10.1

error :

$ git commit -m "message"
husky > pre-commit (node v16.16.0)
Stashing changes... [started]
Stashing changes... [skipped]
→ No partially staged files found...
Running linters... [started]
Running tasks for {,src/**/}*.{json,md,yml,ts,css,scss} [started]
prettier --write [started]
prettier --write [failed]
→ × prettier --write got an unexpected error.
spawn UNKNOWN
Running tasks for {,src/**/}*.{json,md,yml,ts,css,scss} [failed]
→ × prettier --write got an unexpected error.
spawn UNKNOWN
Running linters... [failed]
× prettier --write got an unexpected error.
spawn UNKNOWN
husky > pre-commit hook failed (add --no-verify to bypass)

I can't figure out what is missing ! Could you please help me?

1 Answers

Husky is used by JHipster to install a git pre-commit hook that is run by git before doing a commit, if this script fails then the commit is not executed.

You can see the script, it's .husky/pre-commit it runs Prettier to format your code.

So you have 2 choices:

As your project was generated your by an old version of JHipster, it would probably be a good first step to update Prettier's version and its plugins in package.json and run npm install.

Personal opinion

I think it's a bad idea to keep this hook because it's not documented and because I think it's your IDE's job to format your code and overtime Prettier can fail because you are now using a newer version of Java or Typescript with new syntax. To me, it creates technical debt for future maintainers of your project.

Related