I turn on SWR on my working computer crashes
(Error: The specified module could not be found.
\\?\C:\srcProjects\frontend\node_modules\next\node_modules\@next\swc-win32-x64-msvc\next-swc.win32-x64-msvc.node
at Object.Module._extensions..node (internal/modules/cjs/loader.js:1144:18)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:93:18)
at loadNative (C:\srcProjects\frontend\node_modules\next\dist\build\swc\index.js:84:28)
at loadBindings (C:\srcProjects\frontend\node_modules\next\dist\build\swc\index.js:41:32)
at async Object.isWasm (C:\srcProjects\frontend\node_modules\next\dist\build\swc\index.js:146:20)
at async C:\srcProjects\frontend\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)
I turn it on at home, everything is ok (both there and there Windows)
According to official Next.js docs.
Link here https://nextjs.org/docs/messages/failed-loading-swc
Why This Message Occurred
Next.js now uses Rust-based compiler SWC to compile JavaScript/TypeScript. This new compiler is up to 17x faster than Babel when compiling individual files and up to 5x faster Fast Refresh. SWC requires a binary be downloaded that is compatible specific to your system. In some cases this binary may fail to load either from failing to download or an incompatibility with your architecture.
Possible Ways to Fix It
When on an M1 Mac and switching from a Node.js version without M1 support e.g. v14 to a version with e.g. v16, you may need a different swc dependency which can require re-installing node_modules npm i --force or yarn install --force
.
Alternatively, you might need to allow optional packages to be installed by your package manager (remove --no-optional flag) for the package to download correctly. If SWC continues to fail to load you can opt-out by disabling swcMinify in your next.config.js or by adding a .babelrc to your project with the following content:
{
"presets": ["next/babel"]
}
If it does not work, then you can also refer to this blog post solving the same problem.
link: https://tutorial.tips/how-to-fix-failed-to-load-swc-binary-nextjs/