Next.js Discord

Discord Forum

Adding Prettier to Next.js

Answered
Horned oak gall posted this in #help-forum
Open in Discord
Horned oak gallOP
With the [official instruction](https://nextjs.org/docs/app/api-reference/config/eslint#with-prettier) on how to add Prettier to Next.js
const eslintConfig = [
  ...compat.config({
    extends: ['next', 'prettier'],
  }),
]

However, my files doesn't look the same, it is
const eslintConfig = [
  ...compat.extends("next/core-web-vitals", "next/typescript", "prettier"),
];

At this point. how do I prettify my code?
1. What command do I need to run?
2. Does it enforce prettier before git committing?
Answered by adam.birds
You can just run prettier . and no it won't auto run before commiting. You can setup a pre-commit hook with husky and lint-staged however.
View full answer

8 Replies

You can just run prettier . and no it won't auto run before commiting. You can setup a pre-commit hook with husky and lint-staged however.
Answer
Here is a link of Chat GPT telling you how to set it up:
https://chatgpt.com/share/67b66caf-e5cc-8011-a351-ef29de42dd01
@adam.birds You can just run `prettier .` and no it won't auto run before commiting. You can setup a pre-commit hook with husky and lint-staged however.
Horned oak gallOP
Thanks. Then what does the instruction from the official doc do? I thought it is some kind of integreation?
Thats is just to sort out the rules. so eslint doesn't clash with prettier etc.
Pteromalid wasp
Hello, Chung
You will need to run "prettier --write ." manually
Or another way is to set up a pre-commit hook
Wish your success