Search code examples
prettierprettier-vscode

Prettier: invalid configuration file even though the file is straight from the docs


So I tried installing the prettier today, I followed the instructions straight from the docs.

npm install --save-dev --save-exact prettier
echo {}> .prettierrc.json

then I create a .prettierignore and copy-pasted what's written in my .gitignore in there. Meanwhile, this is what I wrote in the .prettierrc.json:

{
   "singleQuote": true
}

Now when I run the prettier in the command line:

npx prettier --write src/index.js

I get this error:

PS C:\file-directory> npx prettier --write src/index.js
[error] Invalid configuration file `src\index.js`: JSON Error in C:\file-directory\.prettierrc.json:
[error]
[error] > 1 | ��{
[error]     | ^
[error]   2 |
[error]   3 |    "singleQuote": true
[error]   4 |
[error]
[error] Unexpected token "�" (0xFFFD) in JSON at position 0 while parsing near "��{\u0000\r\u0000\n\u0000 \u0000 \u0000 \u0000\"\u0000s\u0000i\u0000..."
[error]
[error] > 1 | ��{
[error]     | ^
[error]   2 |
[error]   3 |    "singleQuote": true
[error]   4 |
[error]

My json file is not showing any errors in vscode... I have the prettier extension disabled since I want to try it out in the CLI but if I enabled it, it will not work, it shows the same error if I click the "Prettier" in the bottom-right of the vscode so this is definitely a config file problem...


Solution

  • Answered by mthrasher33 in the comment section:

    Ran into the same issue. Deleted the .prettierrc.json then made the file through the Visual Studio IDE, and everything worked. Must not work when making the file through the command line?