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.
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
- Read which field SWC rejects in the error.
- Move it under the correct key and remove any trailing commas or comments.
- Re-run the build.
{
"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.
node -e "JSON.parse(require('fs').readFileSync('.swcrc','utf8'))"How to prevent it
- Keep
.swcrcas strict JSON (no comments, no trailing commas). - Place options under the correct keys like
jsc.parser. - Validate the config in CI before compiling.