It looks like, for whatever reason, there is no configuration file for prettier in the place it is looking for it, namely your root folder.

I would check if a ~\.prettierrc.js file exists, by typing cd ~\ && dir /ah and see if .pretterrc.js shows up. If not, create that file and copy this:

module.exports = {
  trailingComma: "es5",
  tabWidth: 4,
  semi: false,
  singleQuote: true,
};

which is just the default configuration found here: https://prettier.io/docs/en/configuration.html

Answer from Qrow Saki on Stack Overflow
🌐
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 - Instead change the require of prettier.config.js in C:\Users\taku\Documents\GitHub\prettier-test\node_modules\.pnpm\prettier@3.0.0\node_modules\prettier\internal\internal.mjs to a dynamic import() which is available in all CommonJS modules. at f._load (node:electron/js2c/asar_bundle:2:13330) at module.exports (file:///C:/Users/taku/Documents/GitHub/prettier-test/node_modules/.pnpm/prettier@3.0.0/node_modules/prettier/internal/internal.mjs:173:34) at loadJsSync2 (file:///C:/Users/taku/Documents/GitHub/prettier-test/node_modules/.pnpm/prettier@3.0.0/node_modules/prettier/internal/internal.mjs:53
Author   risu729
🌐
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

🌐
GitHub
github.com › prettier › prettier-vscode › issues › 3100
Cannot resolve config if `prettierPath` is defined · Issue #3100 · prettier/prettier-vscode
June 22, 2023 - Summary When using the prettier.prettierPath setting in VS Code, the configuration file cannot be resolved and prettier will not format the current file when editor.formatOnSave is set to true. Github Repository to Reproduce Issue I crea...
Author   leifmarcus
🌐
GitHub
github.com › prettier › prettier-vscode › issues › 3672
Error resolving prettier configuration · Issue #3672 · prettier/prettier-vscode
August 15, 2024 - There was an error while loading. Please reload this page. ... If the Prettier configuration file in your project is in ESM format, you must install Prettier locally in your project using:npm install --save-dev prettier
Published   Apr 29, 2025
🌐
GitHub
github.com › microsoft › vscode › issues › 87312
"Error" - resolving Prettier configuration · Issue #87312 · microsoft/vscode
June 15, 2019 - Fork 34.9k · Star 177k · New issueCopy link · New issueCopy link · Closed · Closed · "Error" - resolving Prettier configuration#87312 · Copy link · Labels · *caused-by-extensionIssue identified to be caused by an extensionIssue identified to be caused by an extension ·
Author   vorousjames
🌐
GitHub
github.com › prettier › prettier-vscode › discussions › 3094
Problems with VS-Code: Invalid host defined options · prettier/prettier-vscode · Discussion #3094
["DEBUG" - 13:41:42] Local prettier module path: '/Users/user/Project/next/node_modules/prettier' ["ERROR" - 13:41:42] Error resolving prettier configuration for /Users/user/Project/next ["ERROR" - 13:41:42] Invalid host defined options TypeError: ...
Author   prettier
🌐
Prettier
prettier.io › docs › configuration.html
Configuration File · Prettier
# Stop the editor from looking for .editorconfig files in the parent directories # root = true [*] # Non-configurable Prettier behaviors charset = utf-8 insert_final_newline = true # Caveat: Prettier won’t trim trailing whitespace inside template strings, but your editor might.
🌐
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?

Find elsewhere
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-vscode › issues › 1045
prettier.configPath don't work · Issue #1045 · prettier/prettier-vscode
September 14, 2019 - There was an error while loading. Please reload this page. ... bugSomething isn't workingSomething isn't workinglockedLocked due to inactivityLocked due to inactivity ... I remove the .prettierrc.js file to my project's root path;and delete the setting "prettier.configPath": "~/.prettierrc.js"
Author   hezhongfeng
🌐
JetBrains
youtrack.jetbrains.com › issue › WEB-35472
It recognizes Prettier configuration in prettier.config.js, but not ...
{{ (>_<) }} This version of your browser is not supported. Try upgrading to the latest stable version. Something went seriously wrong
🌐
GitHub
github.com › prettier › prettier-vscode › issues › 1289
Unable to resolve custom configuration module · Issue #1289 · prettier/prettier-vscode
April 3, 2020 - Summary It seems that version 4.0.0 released a few hours ago breaks importing/using custom Prettier configs. Downgrading to 3.20.0 fixes the issue. I know 4.0.0 would be a breaking change, but I do...
Author   vincerubinetti
🌐
GitHub
github.com › prettier › prettier › discussions › 15167
Invalid prettier configuration file detected · prettier/prettier · Discussion #15167
... The problem seems to be that in the VSCode extension, module objects can't be passed through the RPC boundary between the main extension and the worker process where config is actually read.
Author   prettier
🌐
GitHub
github.com › prettier › prettier-vscode › issues › 3475
Unexpectedly resolving globally installed prettier version · Issue #3475 · prettier/prettier-vscode
July 22, 2024 - (these will not replicate the exact same error, but I believe they indicate the same root cause) Install VSCode prettier extension. Ensure resolve global modules is unchecked in the prettier settings. Create a package.json at ~/package.json.
Author   aramissennyeydd
🌐
DEV Community
dev.to › dmytrych › fixing-prettier-not-working-with-vscode-44ml
Fixing Prettier not working with VSCode - DEV Community
June 9, 2023 - In the opened tab, select 'Default Formatter' - `Prettier'. Prettier can be configured to disable parsing for certain file types - so check that the required files are not included in the prettier-ignore file.
🌐
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…
🌐
GitHub
github.com › prettier › prettier-vscode › issues › 3114
Prettier 3 - Invalid host defined options · Issue #3114 · prettier/prettier-vscode
February 19, 2023 - "INFO" - 2:54:03 PM] Formatting file:///home/file...test.ts ["ERROR" - 2:54:03 PM] Error resolving prettier configuration for /home/file....test.ts ["ERROR" - 2:54:03 PM] Invalid host defined options TypeError: Invalid host defined options at Object.<anonymous> (/home/...node_modules/prettier/index.cjs:600:23) at u._compile (/usr/share/code/resources/app/out/vs/loader.js:4:1271) at Module._extensions..js (node:internal/modules/cjs/loader:1243:10) at Module.load (node:internal/modules/cjs/loader:1058:32) at Module._load (node:internal/modules/cjs/loader:893:12) at f._load (node:electron/js2c/as
Author   leppaott