Skip to content
Latchkey

swc Command: Fast JS/TS Compile in CI

swc is a Rust-based compiler that transpiles JS/TS far faster than Babel.

swc (@swc/cli) is a drop-in-ish, Rust-powered alternative to Babel for transpiling JavaScript and TypeScript. In CI it speeds up library builds and test transforms thanks to its native, multithreaded core.

Common flags

  • --out-dir DIR / -d DIR - compile a directory into DIR
  • --out-file FILE / -o FILE - compile to a single output file
  • --config-file PATH - path to a .swcrc config
  • --source-maps / -s - emit source maps (inline supported)
  • -C jsc.target=es2020 - override config options on the command line
  • --copy-files - copy files that are not compiled
  • --strip-leading-paths - flatten output paths (newer CLI versions)

Example in CI

Transpile a TypeScript src tree to dist with maps using swc:

shell
swc src -d dist --source-maps --copy-files -C jsc.target=es2020

Common errors in CI

  • error: failed to read .swcrc - config missing or malformed JSON
  • Syntax Error - file uses syntax not enabled in jsc.parser settings
  • error: Bindings not found / platform binary missing - install the right @swc/core
  • Caused by: failed to resolve config - wrong --config-file path

Key takeaways

  • swc is a faster Babel substitute backed by a native Rust core.
  • Override config inline with -C key=value instead of editing .swcrc.
  • "Bindings not found" means the @swc/core native binary is wrong for the runner OS/arch.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →