Search code examples
eslintprettier

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


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.


Solution

  • 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]