简体   繁体   中英

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! next-js@0.1.0 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,
    }
  };
};

This issue appears when running next@12.1.6 and happens even if your .babelrc file and next.config.js files are configured to not load swc.

If you downgrade to next@12.1.0 , the swc binary load error should go away.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM