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 .swcrcDiagnose it: is it resolution, transform, or memory?
Bundler failures in CI fall into three families and the error text often points at the wrong one. A module that resolves on your machine and not on the runner is nearly always case sensitivity or a missing optional dependency; a transform error is a config or version mismatch; and an unexplained kill with no stack is the out-of-memory reaper, not a build error at all.
# 1. resolution: does the file exist with EXACTLY that case?
git ls-files | grep -i "the/imported/path"
# 2. transform: what versions is CI actually resolving?
npm ls webpack vite rollup esbuild typescript 2>/dev/null | head -20
# 3. memory: was it killed rather than failed?
# exit 137 = SIGKILL (OOM). Nothing in the bundler log will explain it.
node --max-old-space-size=4096 node_modules/.bin/vite buildCommon 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.
Make the build reproducible before you debug it
- Pin the Node major in
setup-nodeand inengines. A bundler that resolves native bindings will pick a different prebuilt binary across majors. - Delete
node_moduleslocally and reinstall from the lockfile before concluding the runner is at fault; most "works locally" reports are stale local state. - Set
CI=truelocally to reproduce. Several toolchains change behaviour under it, including treating warnings as errors. - Exit code 137 is an out-of-memory kill. Raise
--max-old-space-sizeor move to a larger runner rather than searching the bundler config.
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.