Prettier 3.0.0 TypeError: prettier.resolveConfig.sync is not a function

May 2024 ยท 2 minute read

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.

1

8 Answers

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 [email protected] 

or

npm install --save-dev [email protected] 
7

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.

2

I solved this by downgrading prettier to version 2.8.8

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

1

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.

0

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

Using CRA 4.3 I solved it like this npm i this 3:

"eslint": "^7.32.0", "eslint-plugin-prettier": "^4.2.1", "prettier": "^2.8.0", 

This is a pretty stubborn one. Upgrade to alpha version.

Get more insights here: https://github.com/prettier/eslint-plugin-prettier/issues/562

ncG1vNJzZmirpJawrLvVnqmfpJ%2Bse6S7zGiorp2jqbawutJobm9uYmmGen%2BOqamerKSesrN5kmZnZmhdqcaxscSrqaiqXaW%2FpsDTopyrZaKawLC41Z6aqKaWnrRuv9inmmaho2K7sMCMmmSfrZ6Ywaq7zQ%3D%3D