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
- 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.
.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
.swcrcas 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
SWC "Bindings not found" / wrong @swc/core platform in CIFix SWC "Bindings not found" in CI - the native @swc/core binary for the runner's platform is missing, often…
Babel "Support for the experimental syntax ... isn't currently enabled" in CIFix Babel "Support for the experimental syntax 'X' isn't currently enabled" in CI - the source uses syntax th…
Babel "Cannot find module '@babel/core'" running the CLI in CIFix "Cannot find module '@babel/core'" in CI - @babel/cli or a loader needs @babel/core as a peer, but it is…