TO START:

Its helpful to know which "settings.json" your configuring. You need to make sure that both your workspace ".vscode/settings.json" file, and your user "settings.json" file (path is contingent on the O.S. your running) are configured to work harmoniously, and that one is not overriding the other with the same configuration twice.

SECONDLY

Remove all configurations you added to your "./settings.json" file for prettier. Those settings were added by the extension author. Despite the esbenp.prettier-vscode being the official prettier extension for VS Code, Prettier was never intended to be configured via VS Code's configuration files. Prettier is very nit-picky about its "./.prettierrc" configuration file. When we use the VS Code config ("settings.json") when attempt to use a prettier config that the extension generates somewhere. If you end up with settings in some project workspace vscode configurations (e.g. ".vscode/settings.json" files) the extension will try to regenerate a file each time one loads a prettier setting. It may even try to load multiple, depending on the scope of your settings.json file. Some how it has to handle that the user-scoped settings.json file should always be overriden by a workspace "settings.json" configuration file. That's not to mention that prettier configs often contain there own overridden rule sets within the ".prettierrc" configuration file.

  • Note: Just FYI, the most problematic configuration your using is the "prettier.configPath" setting.

_I'm going to stop going down the rabbit hole, hopefully you get the point I am making, which is: Don't use VS Code settings.json configuration files to configure "Prettier".


This will be more easy to explain with a bullet-list

The following will help you configure a clean environment, one where Prettier will work as you have configure it to work.

To start...

  1. ...delete all Prettier settings that you added to all settings.json files. This includes any Prettier settings you added to project ".vscode/settings.json" files, and it especially includes all Prettier-settings that you added to your user "settings.json" file. After you finish, reload VS Code, by closing it out completely, and reopening it.


  1. Rather than delete all prettier configuration files from any projects you have open, I am going to instead ask that when you reopen VS Code, that you only open one instance of VS Code. If VS Code opens a project (aka project-folder) after restarting, you're going to want to close that project w/o opening another one. To do that you can...
    • Use the keybinding ALT + K followed by the F key.
    • Alternatively you can use the title-bar menu like so: FILE  >>  CLOSE FOLDER

Additionally, make sure all tabs are closed as well.



  1. At this point your instance of VS Code should be totally empty, completely a blank canvas. From here you are going to want to create a new file. To do this...

    • You have one of two options

      • (A) You can use the keybinding CTRL + ALT + SUPER + N
      • (B) Another way to achieve the same thing is to use the title-bar menu like so:   FILE  >>  NEW FILE
    • Once you've prompted VS Code to create a new file VS Code will want you to pick a location where it's to be created at. The location doesn't matter, so long as it is in a completely empty file, with nothing else in it. To name the file, VS Code will probably use the drop-down that is often refereed to as the quick input menu. The file needs to be a JavaScript file, as a consequence, the file must end with the file extension ".js". So I can reference the file later, I will call mine "main.js", but you can call your whatever you want, so long as you know which file I am referencing when you read "main.js".

    • In the same folder as "main.js", create one more new file without a file extension. This file MUST HAVE THE NAME...

    • .prettierrc

NOTE: "The file has a period (or dot) as the first character in its name (this makes it a hidden file)."



  1. Add the following prettier configuration to the ".prettierrc" file you just created.
Copy{
  "trailingComma": "es5",
  "tabWidth": 4,
  "semi": true,
  "singleQuote": true
}


  1. **Execute the following commands"
    1. Copy $ npm init
      
      • The command will ask a bunch of questions, just press enter for each one to quickly configure the environment with the default npm/Node.js configuration.
      • The purpose of this is simply to create a valid "package.json" file.
    2. Copy   $ sudo npm i -g prettier && npm i -D prettier
      
         // Or you can execute it as two commands, like this:
      
         $ sudo npm i -g prettier
         $ npm i -D prettier
      
      • The command (or commands, depending on how you enter them) install prettier as a project dependency, and as a global Node.js package.

NOTE: "Make sure that you have prettier installed as a vscode extension. And make sure that you have only one prettier extension. Having multiple can create problems and confusion. The one you should have should have the Extension ID: esbenp.prettier-vscode "



  1. Prettier Should work now. Use the main.js file we created early to write some javascript, then press F1 to open the quick input, type the word "format document", until you see the option "Format Document", which you want to click. Then choose prettier from the menu. Prettier won't format if you have erroneous code, it needs to be free from error. (if you want to fix errors use a linter like ESLint).

You can add a bunch of blank lines, or put braces on the wrong line, leave out semi colons, and prettier should format all of those mistakes.




Answer from JAYD3V on Stack Overflow
Top answer
1 of 6
20

TO START:

Its helpful to know which "settings.json" your configuring. You need to make sure that both your workspace ".vscode/settings.json" file, and your user "settings.json" file (path is contingent on the O.S. your running) are configured to work harmoniously, and that one is not overriding the other with the same configuration twice.

SECONDLY

Remove all configurations you added to your "./settings.json" file for prettier. Those settings were added by the extension author. Despite the esbenp.prettier-vscode being the official prettier extension for VS Code, Prettier was never intended to be configured via VS Code's configuration files. Prettier is very nit-picky about its "./.prettierrc" configuration file. When we use the VS Code config ("settings.json") when attempt to use a prettier config that the extension generates somewhere. If you end up with settings in some project workspace vscode configurations (e.g. ".vscode/settings.json" files) the extension will try to regenerate a file each time one loads a prettier setting. It may even try to load multiple, depending on the scope of your settings.json file. Some how it has to handle that the user-scoped settings.json file should always be overriden by a workspace "settings.json" configuration file. That's not to mention that prettier configs often contain there own overridden rule sets within the ".prettierrc" configuration file.

  • Note: Just FYI, the most problematic configuration your using is the "prettier.configPath" setting.

_I'm going to stop going down the rabbit hole, hopefully you get the point I am making, which is: Don't use VS Code settings.json configuration files to configure "Prettier".


This will be more easy to explain with a bullet-list

The following will help you configure a clean environment, one where Prettier will work as you have configure it to work.

To start...

  1. ...delete all Prettier settings that you added to all settings.json files. This includes any Prettier settings you added to project ".vscode/settings.json" files, and it especially includes all Prettier-settings that you added to your user "settings.json" file. After you finish, reload VS Code, by closing it out completely, and reopening it.


  1. Rather than delete all prettier configuration files from any projects you have open, I am going to instead ask that when you reopen VS Code, that you only open one instance of VS Code. If VS Code opens a project (aka project-folder) after restarting, you're going to want to close that project w/o opening another one. To do that you can...
    • Use the keybinding ALT + K followed by the F key.
    • Alternatively you can use the title-bar menu like so: FILE  >>  CLOSE FOLDER

Additionally, make sure all tabs are closed as well.



  1. At this point your instance of VS Code should be totally empty, completely a blank canvas. From here you are going to want to create a new file. To do this...

    • You have one of two options

      • (A) You can use the keybinding CTRL + ALT + SUPER + N
      • (B) Another way to achieve the same thing is to use the title-bar menu like so:   FILE  >>  NEW FILE
    • Once you've prompted VS Code to create a new file VS Code will want you to pick a location where it's to be created at. The location doesn't matter, so long as it is in a completely empty file, with nothing else in it. To name the file, VS Code will probably use the drop-down that is often refereed to as the quick input menu. The file needs to be a JavaScript file, as a consequence, the file must end with the file extension ".js". So I can reference the file later, I will call mine "main.js", but you can call your whatever you want, so long as you know which file I am referencing when you read "main.js".

    • In the same folder as "main.js", create one more new file without a file extension. This file MUST HAVE THE NAME...

    • .prettierrc

NOTE: "The file has a period (or dot) as the first character in its name (this makes it a hidden file)."



  1. Add the following prettier configuration to the ".prettierrc" file you just created.
Copy{
  "trailingComma": "es5",
  "tabWidth": 4,
  "semi": true,
  "singleQuote": true
}


  1. **Execute the following commands"
    1. Copy $ npm init
      
      • The command will ask a bunch of questions, just press enter for each one to quickly configure the environment with the default npm/Node.js configuration.
      • The purpose of this is simply to create a valid "package.json" file.
    2. Copy   $ sudo npm i -g prettier && npm i -D prettier
      
         // Or you can execute it as two commands, like this:
      
         $ sudo npm i -g prettier
         $ npm i -D prettier
      
      • The command (or commands, depending on how you enter them) install prettier as a project dependency, and as a global Node.js package.

NOTE: "Make sure that you have prettier installed as a vscode extension. And make sure that you have only one prettier extension. Having multiple can create problems and confusion. The one you should have should have the Extension ID: esbenp.prettier-vscode "



  1. Prettier Should work now. Use the main.js file we created early to write some javascript, then press F1 to open the quick input, type the word "format document", until you see the option "Format Document", which you want to click. Then choose prettier from the menu. Prettier won't format if you have erroneous code, it needs to be free from error. (if you want to fix errors use a linter like ESLint).

You can add a bunch of blank lines, or put braces on the wrong line, leave out semi colons, and prettier should format all of those mistakes.




2 of 6
3

After creating a new .prettierrc.json file in a NextJS project and attempting to configure Prettier via .vscode/settings.json (with the Prettier VSCode extension running), I also kept running into Prettier Output errors.

I updated my .vscode/settings.json file to {}, and like the above comment, Prettier now works as expected.

🌐
GitHub
github.com › prettier › prettier › discussions › 15167
Invalid prettier configuration file detected · prettier/prettier · Discussion #15167
For the VSCode extension to work, the Prettier config must be effectively plain old data (specifically, the HTML structured clone algorithm) due to restrictions in worker_threads from the way the VSCode extension is implemented. I ran into this while trying to get a plugin to load under PNP, and it seems like there is no way to make the VSCode extension work.
Author   prettier
🌐
Reddit
reddit.com › r/reactjs › [error] invalid prettier configuration file detected. prettier not working with .cjs or js formats, only json
r/reactjs on Reddit: [Error] Invalid prettier configuration file detected. Prettier not working with .cjs or js formats, only JSON
July 12, 2023 -

I am using vite for my project, and when i do ctrl + s, and look at the output of prettier in the console, it says

["ERROR" - 10:58:51 AM] Invalid prettier configuration file detected.

When I change my prettier.config.js to JSON format, it works fine, but I want it as .cjs so that I can use the following in my prettier file. I am trying to get the sorting for classes working (I am new to tailwind css)

module.exports = { plugins: [require('prettier-plugin-tailwindcss')], }

I am attaching my github repo as well, maybe this can help. thanks. https://github.com/ForkEyeee/memory-card

edit: i got prettier working by changing the prettier.config.cjs to

// prettier.config.cjs
module.exports = { trailingComma: "all", tabWidth: 2, semi: true, singleQuote: true, printWidth: 120, bracketSpacing: true, tailwindConfig: "./styles/tailwind.config.js", };

and now prettier works, but the sorting of classes in tailwind still doesnt work, not sure why

🌐
Reddit
reddit.com › r/learnprogramming › invalid prettier configuration file detected. see log for details.
r/learnprogramming on Reddit: Invalid prettier configuration file detected. See log for details.
October 4, 2022 -

Every time I try to format any of my projects with Prettier it comes back with the following error:

Error: ENOENT: no such file or directory, open '/Users/myname/code/test/.prettierrc' ["ERROR"] Invalid prettier configuration file detected. See log for details.

It worked perfectly fine before and it’s configured to format on save. Does anyone know what to do?

🌐
Cursor
forum.cursor.com › support › bug reports
Prettier formatter not finding project local .prettierrc configuration file - Bug Reports - Cursor - Community Forum
November 18, 2024 - In my project root, I have an .prettierrc.json file dictating formatting. I have a setup imported from vscode, working there but causes an error message in Cursor. In cursor I get this error message: ["INFO" - 11:04:19] Formatting file:///Users/qludelw/dev/aws/.vscode/settings.json ["ERROR" - 11:04:19] Invalid prettier configuration file detected.
🌐
GitHub
github.com › prettier › prettier-vscode › issues › 3071
Prettier does not format documents in latest Prettier + VS code versions · Issue #3071 · prettier/prettier-vscode
May 25, 2023 - I updated to the latest prettier extension + regular vs code update and it just stopped working. ... Version: 1.80.0 (user setup) Commit: 660393deaaa6d1996740ff4880f1bad43768c814 Date: 2023-07-04T15:06:02.407Z Electron: 22.3.14 ElectronBuildId: 21893604 Chromium: 108.0.5359.215 Node.js: 16.17.1 V8: 10.8.168.25-electron.0 OS: Windows_NT x64 10.0.19044 ... ["INFO" - 10:51:46 AM] Formatting file:///..........(path was removed from log) ["INFO" - 10:51:46 AM] Attempted to load Prettier module from /usr/lib/node_modules/prettier ["ERROR" - 10:51:46 AM] Failed to load module.
Author   OmerMessing
🌐
GitHub
github.com › prettier › prettier-vscode › issues › 3066
Cannot use `import` in `prettier.config.js` with Prettier v3 and ESM · Issue #3066 · prettier/prettier-vscode
June 3, 2023 - Summary Format fails if prettier.config.js is written in ESM and contains import for plugins. Github Repository to Reproduce Issue https://github.com/risu729/prettier-test Steps To Reproduce: Create prettier.config.js with {"type": "modu...
Author   risu729
🌐
GitHub
github.com › prettier › prettier-vscode › issues › 1292
Version 4: Invalid prettier configuration detected when using a config from an npm package. · Issue #1292 · prettier/prettier-vscode
March 2, 2020 - When I try to use the formatter, however, it fails, telling me my prettier config is invalid. Cannot find module '@lusito/prettier-config' from '<my-root-path>' Link to a Github repo that can be used to reproduce the issue. ... Install a prettier config, for example mine: @lusito/prettier-config. Create a .prettierrc.json with content "@lusito/prettier-config" ... Prettier Extension Version: 4.0.0. It works when I switch back to 3.2.0 (though trailing commas seems to be different for some reason)
Author   Lusito
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 72628428 › getting-invalid-prettier-configuration-file-detected-error
visual studio code - Getting "Invalid prettier configuration file detected" error - Stack Overflow
Also, I have set the prettier as default formatter in my settings.json file · The problem is that is not giving any information of what the problem is with the config file. And it says that See log for details.
🌐
GitHub
github.com › prettier › prettier-vscode › issues › 3251
Unable to resolve string JSON config which resolves a pure ESM prettier config · Issue #3251 · prettier/prettier-vscode
July 2, 2023 - ["INFO" - 23:38:02] Formatting file:///Users/JounQin/Workspaces/GitHub/preversion/package.json ["ERROR" - 23:38:02] Invalid prettier configuration file detected. {} ["ERROR" - 23:38:02] Invalid prettier configuration file detected. See log for details. No one assigned ·
Author   JounQin
🌐
GitHub
github.com › prettier › prettier-vscode › issues › 3623
BUG: Does not support `prettier.config.ts`, recently added in Prettier `v3.5.0` · Issue #3623 · prettier/prettier-vscode
January 9, 2025 - ["ERROR" - 8:16:51 PM] Unknown file extension ".ts" for /path/to/prettier.config.ts TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /path/to/prettier.config.ts at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:177:9) at defaultGetFormat (node:internal/modules/esm/get_format:220:36) at defaultLoad (node:internal/modules/esm/load:142:22) at async ModuleLoader.load (node:internal/modules/esm/loader:555:7) at async ModuleLoader.moduleProvider (node:internal/modules/esm/loader:434:45) at async link (node:internal/modules/esm/module_job:87:21) ["ERROR" - 8:16:51 PM] Invalid prettier configuration file detected. See log for details.
Author   taep96
🌐
GitHub
github.com › prettier › prettier-vscode › issues › 3718
Module based files are not supported · Issue #3718 · prettier/prettier-vscode
February 2, 2025 - Summary I am trying to use the mjs file types in my project as the prettier configuration file. Steps To Reproduce: Create a prettier config with the mjs extension Change the settings.json of your workspace to target the configuration fi...
Author   Codeonkey
🌐
Lightrun
lightrun.com › answers › prettier-prettier-json-error-in-prettierrcjson-linesandcolumns1-is-not-a-constructor
JSON Error in .prettierrc.json: LinesAndColumns$1 is not a constructor
I am getting the same error from the CLI, but I don’t know how to get a stack trace/detailed logs from there, so here is the vscode “format on save” error logs that get spit out. ["ERROR" - 12:01:41 PM] Invalid prettier configuration file detected.
🌐
Medium
medium.com › @seohyoda › vscode-에서-prettier-오동작-해결-a4327a97bd93
VSCODE 에서 prettier 오동작 해결
June 4, 2023 - This package disables ESLint rules that conflict with Prettier, ensuring compatibility between the two tools. Install the package using the following command: ... 4. Once the installation is complete, modify the extends section in your .eslintrc.js or .eslintrc.json file to enable eslint-config-prettier.
🌐
Prettier
prettier.io › docs › configuration
Configuration File · Prettier
// prettier.config.js, .prettierrc.js, prettier.config.mjs, or .prettierrc.mjs /** * @see https://prettier.io/docs/configuration * @type {import("prettier").Config} */ const config = { trailingComma: "es5", tabWidth: 4, semi: false, singleQuote: true, }; export default config;
🌐
Stack Overflow
stackoverflow.com › questions › tagged › prettier
Newest 'prettier' Questions - Page 7 - Stack Overflow
Just spun up a new React project and decided to use Prettier in it. However, in all of my .tsx files Prettier reports syntax errors on the first line of JSX.
🌐
GitHub
github.com › prettier › prettier-vscode › blob › main › src › message.ts
prettier-vscode/src/message.ts at main · prettier/prettier-vscode
See log for details."; export const RESTART_TO_ENABLE = "To enable or disable prettier after changing the `enable` setting, you must restart VS Code."; export const USING_BUNDLED_PRETTIER = "Using bundled version of prettier."; export const ...
Author   prettier