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
npmjs.com › package › prettier-package-json
prettier-package-json - npm
prettier-package-json is a JSON formatter inspired by prettier. It removes all original styling and ensures that the outputted package.json conforms to a consistent style.
      » npm install prettier-package-json
    
Published   Dec 23, 2022
Version   2.8.0
Author   Cameron Hunter
🌐
Prettier
prettier.io › docs › configuration
Configuration File · Prettier
{ "overrides": [ { "files": ".prettierrc", "options": { "parser": "json" } } ] }
🌐
npm
npmjs.com › package › prettier-plugin-packagejson
prettier-plugin-packagejson - npm
A Prettier plugin to sort the keys of a package.json file using sort-package-json.
      » npm install prettier-plugin-packagejson
    
🌐
GitHub
github.com › matzkoh › prettier-plugin-packagejson
GitHub - matzkoh/prettier-plugin-packagejson: Prettier plugin for package.json
A Prettier plugin to sort the keys of a package.json file using sort-package-json.
Starred by 382 users
Forked by 11 users
Languages   JavaScript 90.7% | TypeScript 9.3% | JavaScript 90.7% | TypeScript 9.3%
🌐
GitHub
github.com › cameronhunter › prettier-package-json
GitHub - cameronhunter/prettier-package-json: Prettier formatter for package.json files · GitHub
prettier-package-json is a JSON formatter inspired by prettier. It removes all original styling and ensures that the outputted package.json conforms to a consistent style.
Starred by 157 users
Forked by 18 users
Languages   TypeScript 85.6% | JavaScript 14.4%
🌐
GitHub
github.com › prettier › prettier › blob › main › package.json
prettier/package.json at main · prettier/prettier
"debug": "node bin/prettier.js --ignore-path=.prettierignore --plugin=./packages/plugin-oxc/index.js --plugin=./packages/plugin-hermes/index.js", "debug:watch": "node --watch bin/prettier.js --ignore-path=.prettierignore --plugin=./packages/plugin-oxc/index.js --plugin=./packages/plugin-hermes/index.js", "debug:inspect": "node --inspect-brk bin/prettier.js --ignore-path=.prettierignore --plugin=./packages/plugin-oxc/index.js --plugin=./packages/plugin-hermes/index.js" }, "c8": { "reporter": [ "lcov", "text" ], "all": true, "include": [ "src/**",
Author   prettier
🌐
Medium
medium.com › @martin_hotell › stop-re-formatting-package-json-with-prettier-and-vscode-once-and-for-all-52d283067f9a
Stop re-formatting package.json with Prettier and VSCode once and for all | by Martin Hochel | Medium
March 19, 2018 - Now you, go to package.json or tsconfig.json, you change something, hit save… bang! Whole json file re-formatted. That’s good indeed right?!… well, until it isn’t. Now, let’s say, one of your colleague, which is using some other editor without all that prettier fancy stuff goes to package.json and changes something, or he adds some new package via yarn add 50-50-grind
Find elsewhere
🌐
Prettier
prettier.io › docs › sharing-configurations
Sharing configurations · Prettier
First, create a new package. We recommend creating a scoped package with the name @username/prettier-config. A minimal package should have at least two files. A package.json for the package configuration and an index.js which holds the shared prettier configuration object:
🌐
GitHub
github.com › shellscape › prettier-plugin-package
GitHub - shellscape/prettier-plugin-package: An opinionated package.json formatter plugin for Prettier
Prettier is an opinionated code formatter. It enforces a consistent style by parsing your code and re-printing, taking various rules into account. This plugin adds support for package.json files used within NPM modules.
Starred by 92 users
Forked by 4 users
Languages   JavaScript 100.0% | JavaScript 100.0%
🌐
GitHub
github.com › prettier › eslint-config-prettier › blob › main › package.json
eslint-config-prettier/package.json at main · prettier/eslint-config-prettier
"test": "yarn test:prettier && ESLINT_CONFIG_PRETTIER_NO_DEPRECATED=true yarn test:with-env && ESLINT_USE_FLAT_CONFIG=false yarn test:with-env", "test:cli-sanity": "node ./bin/cli.js index.js", "test:cli-sanity-warning": "node ./bin/cli.js react.js ./bin/cli.js", "test:deprecated": "eslint-find-rules --deprecated index.js", ... "test:lint-verify-fail": "eslint \"test-lint/*.{js,jsx,ts,vue}\" --config .eslintrc.base.js --format json",
Author   prettier
🌐
Prettier
prettier.io › docs › install
Install · Prettier
If you forget to install Prettier first, npx will temporarily download the latest version. That’s not a good idea when using Prettier, because we change how code is formatted in each release! It’s important to have a locked down version of Prettier in your package.json.
🌐
GitHub
github.com › prettier › prettier-vscode › issues › 163
Support Prettier config from prettierrc and package.json · Issue #163 · prettier/prettier-vscode
July 12, 2017 - A .prettierrc file, written in YAML or JSON. A prettier.config.js file that exports an object. A "prettier" key in your package.json file.
Author   bajtos
🌐
DEV Community
dev.to › bokub › how-to-properly-set-up-prettier-in-less-than-2-minutes-2ld0
How to properly set up Prettier in less than 2 minutes - DEV Community
July 5, 2022 - // .prettierrc.js module.exports = { tabWidth: 4, singleQuote: true, }; N.B: You can find the list of all available options here. The name of each option should be the one from the “API Override” section. I personally always use the same options, which are the default ones, plus: ... If you want to use my set of options, it’s super easy, add the following line to your package.json
🌐
Bitstack
blog.bitsrc.io › add-prettier-to-your-project-d7e91ac03d05
How to Add Prettier to a Project. Format code in your project with… | by Ivo Nederlof | Bits and Pieces
March 4, 2025 - Add files or folders you want to to ignore, for example: ./dist · In your package.json, add "format": "npx prettier --write ." in the scripts section: ... "version": "0.0.0", "scripts": { "start": "node index.js", "format": "npx prettier --write ."
🌐
Medium
medium.com › @clairecodes › note-at-the-time-of-writing-prettier-is-on-version-1-14-2-ddc5e7cd9a92
My Prettier Cheatsheet. Note: at the time of writing, Prettier… | by Claire Parker-Jones | Medium
October 30, 2018 - 1) Create a file called .prettierrc in the root of your project. Many file formats are valid but I prefer JSON. Copy and paste the JSON above into the file. 2) Add the options to the package.json script in the CLI format:
🌐
Stack Overflow
stackoverflow.com › questions › 65861816 › npm-and-have-package-json-file-for-prettier
NPM and have package.json file for Prettier - Stack Overflow
If it is javascript based then in root folder open cmd and type "npm init" this will create package.json automatically. ... Sign up to request clarification or add additional context in comments. ... I have VSCode. Just installed node-v14.15.4-x64. Then I installed Prettier but it does nothing.
🌐
npm
npmjs.com › package › prettier-plugin-sort-json
prettier-plugin-sort-json - npm
Prettier plugin to sort JSON files alphanumerically by key. Latest version: 4.2.0, last published: 2 months ago. Start using prettier-plugin-sort-json in your project by running `npm i prettier-plugin-sort-json`. There are 72 other projects ...
      » npm install prettier-plugin-sort-json
    
🌐
JetBrains
jetbrains.com › help › webstorm › prettier.html
Prettier | WebStorm Documentation
The project has a .prettierrc configuration file in the project root. There are also four package.json files, one of them is in the project root, the others are in subprojects. As you can see, Prettier is listed as dependency only in the package.json from the packages/package_c_with_prettier_dependency subproject.