I ran into this error while using a .prettierrc.json file, and the problem was that the file was encoded in UTF-16LE, not UTF-8. Saving the file as UTF-8 fixed this for me.
The root cause of this issue was following the documentation that recommended echo {}> .prettierrc.json to create the file. On Windows powershell, this creates a UTF-16LE file, not a UTF-8 file.
More discussion can be found at this github issue
Answer from Luke Miller on Stack Overflow
» npm install prettier-package-json
Videos
I ran into this error while using a .prettierrc.json file, and the problem was that the file was encoded in UTF-16LE, not UTF-8. Saving the file as UTF-8 fixed this for me.
The root cause of this issue was following the documentation that recommended echo {}> .prettierrc.json to create the file. On Windows powershell, this creates a UTF-16LE file, not a UTF-8 file.
More discussion can be found at this github issue
According to https://prettier.io/docs/en/configuration.html configuration in package.json has the highest precedence, so you should be able to call:
prettier ./src/basic-sample.js
or
prettier --write ./src/basic-sample.js
I'm doing this from within an package.json script, but that shouldn't make any difference.
» npm install prettier-plugin-packagejson
you can also use a .prettierignore file.
See the prettier project itself for a reference.
The limitation here is due to how lint-staged is used. I personally end up using a simple command (fast enough for me), without lint-staged (but still using husky+precommit).
prettier --write "**/*.{js,json,css,md}" !package.json
This command is in my package.json as a "format" script.
"precommit": "yarn format", // can be "npm run format"
"format": "prettier --write \"**/*.{js,json,css,md}\" \"!package.json\""
Please note the escaped quotes.
» npm install prettier-plugin-sort-json