Skip to content
Latchkey

SWC "failed to parse .swcrc" - Fix SWC Config Errors in CI

SWC could not load or apply your .swcrc. Either the file is not valid JSON, it contains an option SWC does not recognize, or the jsc.parser/jsc.target does not match the code being compiled.

What this error means

A build using @swc/core (directly, via swc-loader, or through a tool) fails with failed to parse config file or unknown variant, naming the bad key. It reproduces identically every run.

swc output
thread 'main' panicked at 'failed to parse config file':
unknown variant `es2025`, expected one of `es3`, `es5`, ... `es2022`
  at jsc.target in .swcrc

Common causes

Invalid JSON or unknown option

A trailing comma, comment, or a jsc.target/option value SWC does not support for the installed version makes config parsing fail.

Parser does not match the syntax

A jsc.parser set to ecmascript for TypeScript files (or tsx: false for files containing JSX) makes SWC reject valid source as a parse error.

How to fix it

Write a valid .swcrc for your syntax

Use strict JSON, a supported jsc.target, and a parser matching the files.

.swcrc
// .swcrc
{
  "jsc": {
    "parser": { "syntax": "typescript", "tsx": true },
    "target": "es2022"
  }
}

Align option values with the installed SWC

  1. Check @swc/core version: npm ls @swc/core.
  2. Use a jsc.target the installed version supports (newer targets need newer SWC).
  3. Match parser.syntax to the file type and set tsx/jsx true where the source contains JSX.

How to prevent it

  • Keep .swcrc as strict JSON and validate it in CI.
  • Match jsc.parser to your source (typescript + tsx for TSX).
  • Upgrade @swc/core before using a newer jsc.target value.

Frequently asked questions

What causes ""failed to parse .swcrc""?
A trailing comma, comment, or a jsc.target/option value SWC does not support for the installed version makes config parsing fail.
How do I fix "failed to parse .swcrc"?
Use strict JSON, a supported jsc.target, and a parser matching the files.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card