Pages

Topics

Tools

↑↓navigate↵openescclose
All guides

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.

~5 min readNext.js
#nextjs#swc#native-binaries#build-errors
Bold white headline reading SWC BINARY beside a cyan compiler crate with an amber missing native module slot.

Introduction & Quick Summary

next build (or next dev) stops before compiling anything:

code
Failed to load SWC binary for linux/x64, see more info here: https://nextjs.org/docs/messages/failed-to-load-swc

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

bash
node -e "console.log(process.platform, process.arch, process.versions.node)" ls node_modules/@next rm -rf node_modules .next npm ci

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

json
// 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:

bash
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/*.node

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

bash
# 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.0

Pinning 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

CauseSymptom in node_modules/@nextFix
install omitted optional depsdirectory missing entirelynpm ci without --omit=optional
copied from another archwrong swc-<platform> folderdelete and reinstall on target
Alpine image-gnu folder present, load failsinstall -musl, add libc6-compat
truncated downloadfolder present, no .nodeclear cache and reinstall
version driftfolder at different version than nextpin both to the same version
noexec filesystem.node present, EACCES on loadmount writable and executable
EnvironmentOptional dependency flagResult
npm cioptional installedworks
npm ci --omit=optionalskippedSWC binary missing
yarn install --ignore-optionalskippedSWC binary missing
pnpm install --no-optionalskippedSWC binary missing
pnpm with a strict store on another archresolved for hostwrong binary
Docker multi-stage copycopied from builder platformwrong binary if platforms differ
Where it failsMessage prefixFirst thing to check
next devFailed to load SWC binary for <platform>node_modules/@next
next buildsamebuild image platform
Docker buildsame inside build stagebase image arch vs --platform
CI cache restoresame after a cache hitcache key includes OS and arch
next build after upgradeFailed to load SWC binary plus version textnext 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.

dockerfile
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 --from=deps /app/node_modules ./node_modules COPY . . RUN npm run build

Build with an explicit platform so the install and the runtime agree:

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

bash
pnpm why @next/swc-linux-x64-gnu || echo "not resolved" pnpm store prune rm -rf node_modules pnpm install --frozen-lockfile

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

bash
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:

bash
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:

bash
rm -rf .next node_modules/.cache npm run build

Check 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; deleting node_modules and running npm ci is faster than chasing it.
  • Copying node_modules in 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 documentation

The Next.js documentation that defines the behaviour this guide explains.

Try matching browser tools

All tools

Small utilities that fit Next.js work — they run entirely in this browser tab, so nothing you paste leaves your device.

All Next.js guides

More in Next.js

All Next.js guides

The guides filed next to this one in Next.js, in library order.