部署在 Vercel 上的 Nextjs = 空白页面

时间:2021-01-02 21:22:38

标签: reactjs next.js web-deployment netlify vercel

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

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

我试过了:

  • 在本地检查构建函数:它完美运行。
  • 将默认构建和开发设置更改为这些(没有运气):

enter image description here

  • 我什至尝试在 netlify 上部署(甚至认为我不认为它们支持 i18n,因为 i18n 不支持下一次导出),但我得到了 404 页,这相当于 Vercel 中的空白页。< /li>

我也试过:

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

enter image description here

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

我的错误。 我的 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(); 是问题所在。