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