【问题标题】:Getting 500 | Internal Server Error when using getServerSideProps in NextJS after deploying in Vercel获得 500 |在 Vercel 中部署后在 NextJS 中使用 getServerSideProps 时出现内部服务器错误
【发布时间】:2022-06-15 16:08:19
【问题描述】:

我正在使用 getServerSideProps 在 NextJS 中使用服务器呈现的页面。它在 index.js(根页面)中。 当我在本地进行构建时,网站运行良好。但是当我在 Vercel 中托管这个网站时,它显示 500 |内部服务器错误。

export async function getServerSideProps(context) {
  let params = context.query;

  const job_col = await collection(db, "job_list");
  const job_snap = await getDocs(job_col);
  let jobData = job_snap.docs.map((doc) => ({
    ...doc.data(),
    id: doc.id,
  }));
  
  return {
    props: {
      jobs: jobData,
      params
    },
  };
}

【问题讨论】:

  • 你在vercel中添加环境变量了吗
  • 您在 Vercel 的日志中看到了什么错误?
  • @HussamKhatib 此项目中没有使用环境变量
  • @juliomalves 构建日志看起来不错。 vercel 日志中没有错误。但是根页面返回 500 状态码
  • 我指的不是构建日志,而是函数日志。如果页面抛出 500 错误,Vercel 上会有关于它的日志。

标签: next.js server-side-rendering vercel


【解决方案1】:

这是因为负载很大。将大负载代码部分移动到客户端(useEffect),它将被解析。

【讨论】:

    猜你喜欢
    • 2022-07-07
    • 2013-03-09
    • 2022-01-01
    • 1970-01-01
    • 2022-08-14
    • 1970-01-01
    • 1970-01-01
    • 2021-10-23
    • 2016-10-27
    相关资源
    最近更新 更多