首页 > 解决方案 > Nextjs 部署在 Vercel = 空白页面

问题描述

我设法在 Vercel 上部署了我的 Nextjs 应用程序(使用 getStaticProps + i18n + firebase)。但我得到一个空白屏幕。这是日志:

Status: 200
Duration: 8.18ms
Memory Used: 111 MB

我试过了 :

在此处输入图像描述

我也试过:

  1. 创建一个新的 git 并重新部署。但是在完美部署后我仍然得到一个空的结果,其中包含我所有页面和内容的列表......
  2. 删除 i18n。
  3. 从公共删除 index.html
  4. 删除除一页外的所有页面。
  5. 删除 _document.jsx
  6. 删除除图像等资产之外的所有公用文件夹页面。
  7. 删除包锁定文件。仍然没有任何效果。然而,我在 Vercel 中获得了我的 webapp 的完美预览,但链接转到空白页面。

在此处输入图像描述

任何想法?

标签: reactjsnext.jsweb-deploymentnetlifyvercel

解决方案


我的错。这是我的 getServerSideProps 代码的问题

对此:

export async function getServerSideProps({ req, res }) {
  const data = cookie.parse(req ? req.headers.cookie || "" : document.cookie);

  if (res) {
    if (Object.keys(data).length === 0 && data.constructor === Object) {
      res.end();
    }
  }

  return {
    props: { userId: data.userId }, // will be passed to the page component as props
  };
}

我去了这个:

export async function getServerSideProps({ req, res }) {
  const data = cookie.parse(req ? req.headers.cookie || "" : document.cookie);

  return {
    props: { userId: data.userId }, // will be passed to the page component as props
  };
}

res.end (); 是问题所在。


推荐阅读