【问题标题】:Nextjs deployed on Vercel = blank pageNextjs 部署在 Vercel = 空白页面
【发布时间】:2021-11-10 07:15:46
【问题描述】:

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

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

我试过了:

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

  • 我什至尝试在 netlify 上进行部署(我什至认为他们不支持 i18n,因为 i18n 不支持下一次导出),但我得到一个 404 页面,相当于 Vercel 中的空白页面。

我也试过了:

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

有什么想法吗?

【问题讨论】:

  • 尝试添加一些相关代码,否则我们无法帮助您调试。
  • 如果没有适当的上下文或最少的重现,就不可能调试它。请查看 SO 的指南:stackoverflow.com/help/how-to-ask
  • 无法添加代码,因为我的本地代码运行没有错误,并且项目太大,无法在此处共享。

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


【解决方案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(); 是问题所在。

【讨论】:

    【解决方案2】:
    1. 删除以下内容对我有用:

    "homepage": "https://your-username.github.io/the-repo-project/",
    1. vercel --prod
    2. 你得等一等

    但我认为这取决于项目。

    【讨论】:

      猜你喜欢
      • 2021-04-22
      • 2022-01-02
      • 2021-08-01
      • 1970-01-01
      • 2023-01-18
      • 1970-01-01
      • 1970-01-01
      • 2021-02-14
      • 1970-01-01
      相关资源
      最近更新 更多