How to Run SWC (@swc/core) in CI
SWC is a Rust compiler delivered as per-platform native bindings. CI breaks when the binding for the runner OS/libc is missing.
@swc/core resolves a platform package such as @swc/core-linux-x64-gnu (or -musl on Alpine) via optional dependencies. The wrong libc or an omitted optional dep produces a bindings error.
Why it fails in CI
- Alpine/musl needs the
-muslbinding, not the default-gnuone. - A lockfile from another OS, or
--omit=optional, leaves no usable binding. - A cached node_modules from another platform carries the wrong
.nodebinding.
Install and run it reliably
Install fresh with optional dependencies enabled so the matching binding resolves. On Alpine the musl binding installs automatically with a clean install.
Terminal
# glibc Linux or Alpine: clean install picks the right binding
npm ci
# verify the binding loads
node -e "require('@swc/core'); console.log('swc ok')"Cache & speed
Standard ~/.npm caching covers the binding download. Do not cache node_modules across libc/OS because the native binding differs.
.github/workflows/ci.yml
- uses: actions/cache@v4
with:
path: ~/.npm
key: npm-${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}Common errors
Bindings not found/Failed to load native binding→ optional deps omitted or wrong libc; reinstall.Error loading shared library ld-linuxon Alpine → install the-muslbinding (clean install).invalid ELF header→ reused node_modules from another arch; reinstall fresh.
Key takeaways
- SWC ships per-platform native bindings via optional dependencies.
- Alpine needs the
-muslbinding; a clean install resolves it. - Never reuse node_modules across libc or arch.
Related guides
How to Run esbuild in CI Across PlatformsRun esbuild in CI: let the correct platform binary install via optional dependencies, avoid cross-platform lo…
How to Run TypeORM Migrations and Tests in CIRun TypeORM in CI: install the driver, run migrations against a service database, handle decorators/ts-node,…
How to Make node-gyp Builds Work in CIFix node-gyp build failures in CI: install Python and a C/C++ toolchain, and stop "gyp ERR! find Python" and…
Self-Healing CI: Missing System Packages and Setup GapsA missing system library or tool fails the build until someone installs it. See the manual fix and how self-h…