Next.js: Failed to load SWC binary
The Next.js compiler ships prebuilt native binaries per platform. A failed download, wrong arch or missing optional dependency leaves SWC unloadable.

Introduction & Quick Summary
next build (or next dev) stops before compiling anything:
Failed to load SWC binary for linux/x64, see more info here:
https://nextjs.org/docs/messages/failed-to-load-swcQuick answer: Next.js compiles with SWC, a Rust compiler that ships as a prebuilt native binary. The next package declares platform-specific packages such as @next/swc-linux-x64-gnu and @next/swc-darwin-arm64 as optional dependencies, and one of them is missing or unusable. The fix is almost always to reinstall dependencies so the matching package lands in node_modules/@next, or to install that one package at the exact version of next.
node -e "console.log(process.platform, process.arch, process.versions.node)"
ls node_modules/@next
rm -rf node_modules .next
npm ciThe error is a packaging problem, not a code problem: no source change causes it, and none fixes it. The usual triggers are an install that skipped optional dependencies, a node_modules copied between CPU architectures, an Alpine image without the musl build, and a cache that survived a Next.js upgrade.
Core Mechanics, Signatures & Reproducible Setup
The native package name encodes three things: platform (linux, darwin, win32), architecture (x64, arm64, arm), and the C library or ABI (gnu for glibc, musl for Alpine, msvc for Windows). Next.js loads the one that matches the machine running the build, so the same lockfile produces different package sets on different machines.
// excerpt of next/package.json
"optionalDependencies": {
"@next/swc-darwin-arm64": "15.5.0",
"@next/swc-darwin-x64": "15.5.0",
"@next/swc-linux-arm64-gnu": "15.5.0",
"@next/swc-linux-arm64-musl": "15.5.0",
"@next/swc-linux-x64-gnu": "15.5.0",
"@next/swc-linux-x64-musl": "15.5.0",
"@next/swc-win32-x64-msvc": "15.5.0"
}Because they are optional, a package manager is allowed to skip them and still report success. Anything that suppresses optional dependencies, or installs on one platform and runs on another, leaves a next package that can start and then fail as soon as it asks SWC to parse a file.
A reproducible check on the failing machine:
node -p "process.platform + '-' + process.arch"
# linux-x64
node -p "require('next/package.json').version"
# 15.5.0
ls node_modules/@next
# swc-linux-x64-gnu (must contain a .node file)
ls node_modules/@next/swc-linux-x64-gnu/*.nodeIf the directory is absent, the install skipped it. If it exists but the .node file is missing or unreadable, the download was truncated, the filesystem is mounted noexec, or an antivirus quarantined it. Both cases end with the same message.
# install exactly the build the local next expects
npm install --save-exact @next/swc-linux-x64-gnu@15.5.0
# Alpine: the musl build plus the glibc shim some packages still need
apk add --no-cache libc6-compat
npm install --save-exact @next/swc-linux-x64-musl@15.5.0Pinning the same version as next matters: the binary protocol between the JavaScript wrapper and the native addon is not guaranteed across minor versions, and a mismatch can fail to load or crash mid-compile.
Key Comparison Table
| Cause | Symptom in node_modules/@next | Fix |
|---|---|---|
| install omitted optional deps | directory missing entirely | npm ci without --omit=optional |
| copied from another arch | wrong swc-<platform> folder | delete and reinstall on target |
| Alpine image | -gnu folder present, load fails | install -musl, add libc6-compat |
| truncated download | folder present, no .node | clear cache and reinstall |
| version drift | folder at different version than next | pin both to the same version |
noexec filesystem | .node present, EACCES on load | mount writable and executable |
| Environment | Optional dependency flag | Result |
|---|---|---|
npm ci | optional installed | works |
npm ci --omit=optional | skipped | SWC binary missing |
yarn install --ignore-optional | skipped | SWC binary missing |
pnpm install --no-optional | skipped | SWC binary missing |
pnpm with a strict store on another arch | resolved for host | wrong binary |
| Docker multi-stage copy | copied from builder platform | wrong binary if platforms differ |
| Where it fails | Message prefix | First thing to check |
|---|---|---|
next dev | Failed to load SWC binary for <platform> | node_modules/@next |
next build | same | build image platform |
| Docker build | same inside build stage | base image arch vs --platform |
| CI cache restore | same after a cache hit | cache key includes OS and arch |
next build after upgrade | Failed to load SWC binary plus version text | next version vs @next/swc-* |
Practical Edge Cases, Error Fixes & Deep Dive Code Examples
1. The Docker build that worked locally
A common failure: build the image on an Apple Silicon laptop, deploy to an amd64 cluster. Docker desktop builds linux/arm64 by default on that machine, so @next/swc-linux-arm64-gnu is baked into the layer, and the container on amd64 cannot load it.
FROM node:22-alpine AS deps
WORKDIR /app
RUN apk add --no-cache libc6-compat
COPY package.json package-lock.json ./
RUN npm ci
FROM node:22-alpine AS builder
WORKDIR /app
COPY /app/node_modules ./node_modules
COPY . .
RUN npm run buildBuild with an explicit platform so the install and the runtime agree:
docker buildx build --platform linux/amd64 -t registry.example.com/app:1.4.0 .In a multi-stage Dockerfile the node_modules folder must come from a stage built for the final platform; copying it across platforms is the same mistake in a different shape.
2. CI caches that outlive an architecture change
Cache keys that only hash the lockfile will hand an amd64 runner a cache produced on an arm64 runner. Add the runner OS and architecture to the key, and reinstall rather than trusting a partial hit:
- uses: actions/cache@v4
with:
path: ~/.npm
key: npm-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('package-lock.json') }}The same applies to .next/cache: a stale compiler cache from an older Next.js version can fail alongside the binary error. Delete .next when the error appears right after an upgrade.
3. Package manager specifics
npm ci --omit=optional, yarn install --ignore-optional and pnpm's --no-optional all skip the platform packages. On pnpm, projects that hoist with a custom node-linker sometimes hide the package from the loader's resolution path; running pnpm why @next/swc-linux-x64-gnu shows whether it was resolved at all.
pnpm why @next/swc-linux-x64-gnu || echo "not resolved"
pnpm store prune
rm -rf node_modules
pnpm install --frozen-lockfileIf the lockfile was generated on macOS and the install runs on Linux, npm ci still installs the optional packages for the current platform, because npm records them per platform in the lockfile; an outdated lockfile from an older next can pin a mismatched version, so regenerating it after a next upgrade is the safest step.
4. Alpine, musl and the glibc build
The glibc build does not run on Alpine. The error can appear as Failed to load SWC binary for linux/x64, or later as a Error loading shared library ld-linux-x86-64.so.2 when the binary is loaded directly.
cat /etc/os-release | grep -i alpine
ldd --version | head -1 # musl prints "musl libc"Install the musl package for the same version, or switch the base image to node:22-bookworm-slim where the glibc build works without extra packages. libc6-compat alone does not replace the native addon; it only satisfies shared-library lookups for packages that need glibc symbols.
5. When the binary exists but still fails to load
noexec mounts, SELinux labels and corporate endpoint protection can block loading .node files while the file is present. The tell is that the same node_modules works on another machine with the same architecture:
mount | grep "node_modules\|/workspace" # look for noexec
node -e "process.dlopen({ exports: {} }, 'node_modules/@next/swc-linux-x64-gnu/next-swc.linux-x64-gnu.node')"A permissions error here points at the filesystem, not at Next.js. Move the project to an executable mount, or adjust the mount options in docker run -v.
6. Forcing a clean rebuild after the fix
After installing the right package, remove the old artifacts so the next run cannot reuse a half-compiled cache:
rm -rf .next node_modules/.cache
npm run buildCheck the build log for the SWC line rather than waiting for the error to disappear; a successful compile of the first page means the binary loaded. For inspecting the resulting next.config or environment files while debugging, the env var formatter and YAML checker keep config edits readable.
Common Compilation/Runtime Mistakes & Version Gotchas
- Reinstalling only
next. The platform package is a separate package at the same version; deletingnode_modulesand runningnpm ciis faster than chasing it. - Copying
node_modulesin Docker. It bakes the builder's platform into the image. Install inside the final stage or copy from a stage with the same--platform. - Assuming the error means broken code. Nothing in the error relates to TypeScript or JSX; a syntax error would surface after SWC loads.
- Ignoring the Node version. Next.js 15 requires Node 18.18 or newer, and an unsupported runtime can fail while loading prebuilt binaries; check with
node -p process.versions.node. - Version notes. Since Next.js 12 the platform packages are optional dependencies, so lockfile and install flags decide whether they arrive. Next.js 13 removed the old in-build download step that used to paper over skipped optional dependencies, which is why older CI scripts now fail.
- Diagnosing from the docs link in the message. The URL printed in the error has moved between versions; read the compiler architecture page for the current explanation instead of trusting a 404.
Official documentation: Next.js compiler architecture and the installation guide.
Official references
primary documentationThe Next.js documentation that defines the behaviour this guide explains.
Try matching browser tools
All toolsSmall utilities that fit Next.js work — they run entirely in this browser tab, so nothing you paste leaves your device.
Related Next.js guides
All Next.js guidesModule not found: Can't resolve a package or alias in Next.js
TypeScript and the bundler resolve imports separately. Align path aliases, workspace dependencies, exports conditions and filename case.
Next.js cacheComponents: 'used uncached or runtime data' build error
Cache Components makes the build refuse to guess where the static shell ends. Stream it, cache it with use cache, or declare the route blocking.
Next.js 16 DynamicServerError: cookies(), headers() and fetchCache
Request-time APIs make a route dynamic, and Next 16 replaced the segment configs with Suspense boundaries and use cache. What to delete and what to wrap.
next/font: Failed to fetch a Google font during the build
The font is fetched during the build, not at runtime. Vendor it with next/font/local or give CI and Docker a route out.
More in Next.js
All Next.js guidesThe guides filed next to this one in Next.js, in library order.