reactjs - Nextjs 部署在 Vercel = 空白页面
问题描述
我设法在 Vercel 上部署了我的 Nextjs 应用程序(使用 getStaticProps + i18n + firebase)。但我得到一个空白屏幕。这是日志:
Status: 200
Duration: 8.18ms
Memory Used: 111 MB
我试过了 :
- 在本地检查构建功能:它运行良好。
- 将默认构建和开发设置更改为这些(没有运气):
- 我什至尝试在 netlify 上进行部署(即使我认为他们不支持 i18n,因为 i18n 不支持下一次导出),但我得到一个 404 页面,这相当于 Vercel 中的空白页面。
我也试过:
- 创建一个新的 git 并重新部署。但是在完美部署后我仍然得到一个空的结果,其中包含我所有页面和内容的列表......
- 删除 i18n。
- 从公共删除 index.html
- 删除除一页外的所有页面。
- 删除 _document.jsx
- 删除除图像等资产之外的所有公用文件夹页面。
- 删除包锁定文件。仍然没有任何效果。然而,我在 Vercel 中获得了我的 webapp 的完美预览,但链接转到空白页面。
任何想法?
解决方案
我的错。这是我的 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 (); 是问题所在。
推荐阅读
- java - 单元测试一个简单的内存缓存
- wordpress - 活动图像大小 Woocommerce 产品页面
- sql - 将多个字段合并为一个
- .net-core - 有没有办法在 netcore webapi 应用程序上配置“JwtBearerOptions”?
- java - 数组子集问题 [O(n) 时间复杂度的最小空间]
- python - cached_property 何时重置?
- ios - 从 NSUserDefaults 解码自定义对象数组时出错?
- css - Flexbox div 与滚动固定容器中的另一个重叠
- sql - SQL - 比较 2 个表中的日期,检索最近的
- java - Java 中的 Extends 和 New 有什么区别?