.prettierrc.json and .prettierrc.toml reject a leading UTF-8 BOM

Open
#20,113 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
68/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
javascript, node.js
Domain
cli, tooling

Research direction

Start with the CLI entry point bin/prettier.cjs and reproduce the issue using the provided .prettierrc.json and .prettierrc.toml commands. Trace how these textual configuration files are read, then verify that a single leading UTF-8 BOM is ignored and example.js formats with the expected output.

Written by the indexing model from the issue text.

Description

Environments:

  • Prettier Version: 3.10.0-dev (commit 1a153120)
  • Running Prettier via: CLI
  • Runtime: Node.js v25.6.0
  • Operating System: Windows 11 64-bit
  • Prettier plugins (if any): None

Steps to reproduce:

Create a JavaScript file:

// example.js
const message = "hello";

Create a .prettierrc.json file with a leading UTF-8 BOM:

node -e "require('node:fs').writeFileSync('.prettierrc.json', '\uFEFF{\"semi\":false}\n')"

Run Prettier:

node ./bin/prettier.cjs --config .prettierrc.json example.js

The same issue can be reproduced with TOML:

node -e "require('node:fs').writeFileSync('.prettierrc.toml', '\uFEFFsemi = false\n')"
node ./bin/prettier.cjs --config .prettierrc.toml example.js

For comparison, configuration files containing the same leading BOM work when using JSON5 or YAML.

Expected behavior:

Prettier should ignore a single leading UTF-8 BOM when reading textual configuration files and format the JavaScript file as:

const message = "hello"

This would make the behavior consistent across JSON, TOML, JSON5, and YAML configuration files.

RFC 8259 also allows JSON parsers to ignore a leading BOM for interoperability:

https://www.rfc-editor.org/rfc/rfc8259.html#section-8.1

Actual behavior:

The JSON configuration exits with status code 2:

Invalid configuration for file "example.js":
JSON Error in .prettierrc.json:
Unexpected token "" (\u{feff})

The TOML configuration also exits with status code 2:

Invalid configuration for file "example.js":
TOML Error in .prettierrc.toml:
Invalid TOML document: only letters, numbers, dashes and underscores are allowed in keys

1:  semi = false
    ^
Dominant language
JavaScript
Stars
52.3k
Forks
5k
Avg merge
20h 28m
Merged PRs (30d)
112

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from prettier/prettier

All issues in prettier/prettier

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.