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.
thread 'main' panicked at 'failed to parse config file':
unknown variant `es2025`, expected one of `es3`, `es5`, ... `es2022`
at jsc.target in .swcrcCommon 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
{
"jsc": {
"parser": { "syntax": "typescript", "tsx": true },
"target": "es2022"
}
}Align option values with the installed SWC
- Check
@swc/coreversion:npm ls @swc/core. - Use a
jsc.targetthe installed version supports (newer targets need newer SWC). - Match
parser.syntaxto the file type and settsx/jsxtrue where the source contains JSX.
How to prevent it
- Keep
.swcrcas strict JSON and validate it in CI. - Match
jsc.parserto your source (typescript + tsx for TSX). - Upgrade
@swc/corebefore using a newerjsc.targetvalue.