9

When trying to run the command using Next.js npm run dev shows error - failed to load SWC binary see more info here: https://nextjs.org/docs/messages/failed-loading-swc.

PS D:\web-development\new-project\explore> npm run dev

> dev     
> next dev

ready - started server on 0.0.0.0:3000, url: http://localhost:3000
Error: The specified module could not be found.
\\?\D:\web-development\new-project\explore\node_modules\@next\swc-win32-x64-msvc\next-swc.win32-x64-msvc.node
    at Object.Module._extensions..node (node:internal/modules/cjs/loader:1179:18)
    at Module.load (node:internal/modules/cjs/loader:975:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:999:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at loadNative (D:\web-development\new-project\explore\node_modules\next\dist\build\swc\index.js:84:28)
    at loadBindings (D:\web-development\new-project\explore\node_modules\next\dist\build\swc\index.js:41:32)
    at async Object.isWasm (D:\web-development\new-project\explore\node_modules\next\dist\build\swc\index.js:146:20)
    at async D:\web-development\new-project\explore\node_modules\next\dist\build\webpack\loaders\next-swc-loader.js:62:178 {
  code: 'ERR_DLOPEN_FAILED'
}
error - Failed to load SWC binary, see more info here: https://nextjs.org/docs/messages/failed-loading-swc
PS D:\web-development\new-project\explore>
juliomalves
  • 42,130
  • 20
  • 150
  • 146
MONIRA MONI
  • 151
  • 1
  • 1
  • 7
  • Does this answer your question? [Next failed to load SWC binary](https://stackoverflow.com/questions/69816589/next-failed-to-load-swc-binary) – juliomalves Jan 09 '22 at 16:02

3 Answers3

10

The best way to solve this issue

I solved this issue by removing node_modules and reinstall packages. I think it's the best solution.

Just run

rm -rf node_modules      // Linux
rmdir /S node_modules   // Windows

And them install packages

npm install

Finally run

npm run dev
6

The way I solved it.

In the beginning, I follow the doc link which was given with error.

error - Failed to load SWC binary, see more info here: https://nextjs.org/docs/messages/failed-loading-swc

Go to this link https://nextjs.org/docs/messages/failed-loading-swc and read this doc.

Then go to this link https://swc.rs/. Download the SWC binary prebuild and add the Transpile JavaScript file.

# Download prebuilt binaries
npm i -D @swc/cli @swc/core

# Transpile JavaScript file and emit to stdout
npx swc ./file.js

Alternatively, go to this link https://nextjs.org/docs/messages/failed-loading-swc and create the .babelrc file next to next.config.js. Inserts the code from the doc inside the .babelrc file.

{
    "presets": ["next/babel"]
}

Then "npm run dev" will be fine (but it will use Babel instead of SWC).

todofixthis
  • 1,072
  • 1
  • 12
  • 25
MONIRA MONI
  • 151
  • 1
  • 1
  • 7
0

If your error happen after cloning the project from git you can try my step

i have same problem with you in windows 11 when i clone the project from my old repo. first i try to remove yarn.lock and node_modules, then install the dependencies again, but it doesn't work.

after a few minute, i figure out because i have permission problem. i install git with chocolately as administrator, so, i remove the git from choco

choco uninstall git

the I install git from git scm. you can download it here https://git-scm.com/downloads

after that I clone the project, run yarn and it's work like a charm.

Dharman
  • 30,962
  • 25
  • 85
  • 135