Next.js cannot load its SWC compiler binary
Failed to load SWC binaryShort answer
Next.js compiles with SWC, a native binary shipped as an optional npm package for your platform. The error means that package was not installed or cannot run. Reinstall without skipping optional dependencies, regenerate a lockfile made on another platform, or install the Visual C++ runtime on Windows.
Fix it fast
1Find out which cause you have
Print your platform and check that the matching @next/swc package is in node_modules.
node -p "process.platform + ' ' + process.arch" ls node_modules/@next | grep swc2Match what you see, then jump to its fix
- 1
No @next/swc-* folder in node_modulesOptional dependencies were skippedFix - 2
Works on your laptop, fails in CI or DockerThe lockfile was made on another platformFix - 3
After switching Node.js versions or moving between Intel and Apple siliconnode_modules built for a different CPU architectureFix - 4
Fails on Windows with the platform package presentWindows is missing the Visual C++ RedistributableFix
- 1
What does the error look like?
Failed to load SWC binary
Cause 1 of 4
Optional dependencies were skipped
1Check
The SWC binary comes as an optional dependency. Package managers skip those when told to.
npm config get omit
echo "$NPM_CONFIG_OMIT"2Fix
Install again without omitting optional packages (drop --no-optional or --omit=optional), from a clean node_modules.
rm -rf node_modules
npm install3Verify
The platform package is present and the dev server starts.
ls node_modules/@next | grep swc
npx next devConfirmed by nextjs.org
Cause 2 of 4
The lockfile was made on another platform
1Check
A lockfile generated on one OS can list only that platform's optional packages, so CI cannot install its own.
grep -c "@next/swc" package-lock.json2Fix
Delete the lockfile and regenerate it, using a current npm.
npm i -g npm@latest
rm package-lock.json
npm install3Verify
Run the same install in CI or in a fresh container and start the build.
npm ci && npx next buildConfirmed by nextjs.org
Cause 3 of 4
node_modules built for a different CPU architecture
1Check
The page describes this for an M1 Mac after switching to a Node.js build with arm64 support: the installed swc package no longer matches.
node -p "process.arch"2Fix
Reinstall dependencies with force so the right package is fetched.
npm i --force3Verify
Start the dev server again.
npx next devConfirmed by nextjs.org
Cause 4 of 4
Windows is missing the Visual C++ Redistributable
1Check
The native binary needs the Microsoft Visual C++ Redistributable.
dir node_modules\@next2Fix
Install the latest supported Visual C++ Redistributable from Microsoft, then run the dev server again.
npx next dev3Verify
The compile error is gone.
npx next buildConfirmed by nextjs.org
How do I stop it coming back?
- Do not use flags that skip optional dependencies in CI or Docker builds.
- Commit a lockfile that was generated with a current npm.
- Reinstall dependencies after changing Node.js version or machine architecture.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Web apps
Apollo Server rejects a request as a potential CSRF
HTTP 400 Bad Request from the GraphQL endpoint
Apollo Server's CSRF prevention is on by default.
3 causes, each with a fixWeb apps
Clerk cannot read its publishable key in a Next.js app
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY is undefined
Clerk reads NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY.
3 causes, each with a fixWeb apps
The shell cannot find create-next-app
command not found: create-next-app
create-next-app is not meant to be installed as a shell command.
2 causes, each with a fixWeb apps
ESLint fails with: Cannot find module 'next/babel'
ESLint stops on the first file with a Babel or parser error instead of listing lint results
next/babel is a Babel preset that ships inside the next package.
3 causes, each with a fixWeb apps
Firebase Auth says the API key is not valid
Firebase: Error (auth/api-key-not-valid.-please-pass-a-valid-api-key.)
The apiKey your app sends is either empty, wrong, or blocked.
4 causes, each with a fixWeb apps
Jest fails with SyntaxError: Unexpected token when testing a Next.js component
Jest failed to parse a file.
Jest only understands plain JavaScript until a transform and a few file mappings tell it more.
3 causes, each with a fix