84

The error triggered after I run this command:

npx eslint "the code directory"

This is the first several line of the error

TypeError: prettier.resolveConfig.sync is not a function
Occurred while linting *the first line of the first code directory*  
Rule: "prettier/prettier"
    at Program (*the main directory*\node_modules\eslint-plugin-prettier\eslint-plugin-prettier.js:138:40)

These are eslint, prettier, and the other config taken from package.json

"eslint": "^8.42.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-cypress": "^2.13.3",
"eslint-plugin-prettier": "^4.2.1",
"prettier": "3.0.0",
"prettier-eslint": "^15.0.1"

I've tried delete the files from node_modules and run 'npm i' then restart the IDE (using VS Code), it still happens.

Stephen Senjaya
  • 855
  • 1
  • 2
  • 6
  • The resolveConfig functionality got removed with the release of Prettier v3: https://github.com/prettier/prettier/pull/12788 - This was a breaking change, so tooling relying on this functionality need to upgrade as well. Workaround: Downgrade to Prettier v2. – Benny Code Jul 24 '23 at 15:32

6 Answers6

138

There is an incompatibility between prettier 3 and eslint-plugin-prettier 4.

You can fix this by using version 5 of eslint-plugin-prettier:

yarn add -D eslint-plugin-prettier@5.0.0

or

npm install --save-dev eslint-plugin-prettier@5.0.0
j0k
  • 22,600
  • 28
  • 79
  • 90
Josef Reichardt
  • 2,778
  • 3
  • 22
  • 37
  • 1
    it works, thanks – Stephen Senjaya Jul 06 '23 at 06:33
  • 2
    Using eslint-plugin-prettier alpha and prettier ^3.0.0 breaks the formatting feature from prettier. If we see in 'Format document with...' section, there are so many ESLint listed. Option + Shift + F is also not working. Reverting back to eslint-plugin-prettier ^4.2.1 and prettier ^2.8.8 makes formatting working again. – Jeaf Gilbert Jul 10 '23 at 16:25
  • 3
    The version 5 its not in alpha anymore! =) – Breno Mazieiro Jul 11 '23 at 08:44
  • Works, thank you! or `pnpm add -D eslint-plugin-prettier@latest --save-exact` – elbik Jul 11 '23 at 14:31
  • `stylelint-prettier@3.x.x` and below will not work with prettier v3. You will also need to bump that package to 4.0.0. – esbanarango Aug 14 '23 at 02:00
  • It worth to mention that it seems like `eslint-plugin-prettier` is now a mandatory dependency, which is not updated automatically as peer dependency forcing us to install it explicitly even when it previously not used in a project. Anyway, it helped me too, thanks. – Igor Nikiforov Aug 17 '23 at 16:31
22

In my case, the issue was connected with pretty-quick tool I used for pre-commit formatting. Current version (pretty-quick v3.1.3) is not compatible with prettier v3, they have an issue in their repo (link). And sine the last update of pretty-quick was made 2 years ago, I decided to switch to lint-staged which is compatible with prettier v3 and seems to be more live/maintainable (the last release was made 1 week ago). The transition was super easy, just following the readme doc: https://github.com/okonet/lint-staged.

dhilt
  • 18,707
  • 8
  • 70
  • 85
12

I solved this by downgrading prettier to version 2.8.8

esmoley
  • 197
  • 1
  • 3
7

When downgrading to prettier@^2.8.0 you have to install eslint-plugin-prettier@^4.0.0 for prettier & eslint to work

Bassem
  • 3,582
  • 2
  • 24
  • 47
4

Fixing my issue was simpler and the error was a red herring.

I included all the eslint plugins but forgot to actually include prettier itself.

yarn

yarn add -D prettier

npm

npm i -D prettier

Hope this helps someone else before they get stuck. Thankfully I realized it quickly.

mawburn
  • 2,232
  • 4
  • 29
  • 48
0

In my case i was updating "eslint-plugin-prettier": "4.0" to "5.0" without also updating prettier

Cristian Muscalu
  • 9,007
  • 12
  • 44
  • 76