Skip to content
Latchkey

SWC "failed to read .swcrc file" / parse config in CI

SWC reads .swcrc as JSON before compiling. "failed to read .swcrc file" means the file is invalid JSON or contains an unknown option, so SWC aborts before transforming any source.

What this error means

The build fails with "failed to read .swcrc file" or "error: failed to deserialize" naming the offending field in the config.

swc
error: failed to read .swcrc file
Caused by:
    0: failed to deserialize .swcrc
    1: unknown field `target`, expected one of `syntax`, `tsx`, `jsx`

Common causes

Invalid JSON in .swcrc

A trailing comma or comment makes the file invalid JSON, which SWC cannot parse.

An option in the wrong place

A field nested under the wrong key (for example target outside jsc) is rejected as an unknown field.

How to fix it

Validate and fix the .swcrc structure

  1. Read which field SWC rejects in the error.
  2. Move it under the correct key and remove any trailing commas or comments.
  3. Re-run the build.
.swcrc
{
  "jsc": {
    "parser": { "syntax": "typescript", "tsx": true },
    "target": "es2020"
  }
}

Lint the JSON before building

Parse the config in a pre-step so a malformed .swcrc fails fast with a clear message.

Terminal
node -e "JSON.parse(require('fs').readFileSync('.swcrc','utf8'))"

How to prevent it

  • Keep .swcrc as strict JSON (no comments, no trailing commas).
  • Place options under the correct keys like jsc.parser.
  • Validate the config in CI before compiling.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →