'Why getStaticProps giving error of "Failed to load SWC binary for win32/x64"?
I am using getStaticProps() in a Next.js app but when I run the app it gives ERROR:-
warn - Attempted to load @next/swc-win32-x64-gnu, but it was not installed
warn - Attempted to load @next/swc-win32-x64-msvc, but an error occurred: The specified
module could not be found.
\\?\D:\tasks\next-js\node_modules\@next\swc-win32-x64-msvc\next-swc.win32-x64-msvc.node
error - Failed to load SWC binary for win32/x64, see more info here:
https://nextjs.org/docs/messages/failed-loading-swc
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] dev: `next dev`
npm ERR! Exit status 1
npm ERR!
I tried all methods like uninstalling node_module, package-lock and reinstalling it. I tried adding .babelrc file, also added swcMinify: false in next.config but nothing works.
When I use useEffect instead of getStaticProps then it works fine.
Here is the getStaticProps function:-
export const getStaticProps = async () =>{
const res = await fetch('https://jsonplaceholder.typicode.com/posts');
const data = await res.json();
return{
props: {
data,
}
};
};
Solution 1:[1]
This issue appears when running [email protected]
and happens even if your .babelrc
file and next.config.js
files are configured to not load swc.
If you downgrade to [email protected]
, the swc binary load error should go away.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Caleb Faruki |