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

Diagnose 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.

Terminal
# 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 build

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.

Make the build reproducible before you debug it

  • Pin the Node major in setup-node and in engines. A bundler that resolves native bindings will pick a different prebuilt binary across majors.
  • Delete node_modules locally and reinstall from the lockfile before concluding the runner is at fault; most "works locally" reports are stale local state.
  • Set CI=true locally 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-size or move to a larger runner rather than searching the bundler config.

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 SWC "failed to parse .swcrc"?
There are 2 common causes: invalid json or unknown option and parser does not match the syntax. 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 SWC "failed to parse .swcrc"?
There are 2 fixes depending on which cause you have: write a valid .swcrc for your syntax and align option values with the installed swc. Work through them in order, since the first is the most common.
What does SWC "failed to parse .swcrc" actually mean?
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.
How do I stop SWC "failed to parse .swcrc" happening again?
Keep .swcrc as strict JSON and validate it in CI. The prevention section lists 3 changes that keep it from recurring.

Related guides

References

Not every red build is your code. Latchkey repairs the ones that are not, on the runner. Start free → 30-day trial · No credit card