繁体   English   中英

为什么 getStaticProps 给出“无法为 win32/x64 加载 SWC 二进制文件”的错误?

[英]Why getStaticProps giving error of "Failed to load SWC binary for win32/x64"?

我在 Next.js 应用程序中使用 getStaticProps() 但是当我运行该应用程序时它给出了错误:-

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!

我尝试了所有方法,例如卸载 node_module、package-lock 并重新安装它。 我尝试添加 .babelrc 文件,还在 next.config 中添加了 swcMinify: false 但没有任何效果。
当我使用 useEffect 而不是 getStaticProps 时,它可以正常工作。 这是 getStaticProps 函数:-

export const getStaticProps = async () =>{

const res = await fetch('https://jsonplaceholder.typicode.com/posts');
const data = await res.json();

return{
    props: {
        data,
    }
  };
};

运行next@12.1.6时会出现此问题,即使您的.babelrc文件和next.config.js文件配置为不加载 swc 也会发生。

如果您降级到next@12.1.0 ,则 swc 二进制加载错误应该会消失。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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