如何使用 Next.js 自动静态站点优化并仍然导出 Netlify?

How to use Next.js Automatic Static Site Optimization and still export for Netlify?

我一直致力于实现 Next 9.3 的一些更新。我一直在从 getInitialProps 移动到 getServerSideProps,并注意到我的 exportPathMap 对这些页面变得动态变得不满意。一切正常 运行ning next,但是当我转到 运行 next build && next export 时,我 运行 遇到了一些问题。

static html export 的文档中指出 If your pages don't have getInitialProps you may not need next export at all; next build is already enough thanks to Automatic Static Optimization. 当我 运行 next build && next start.我需要采取哪些步骤才能使其也与 next export 一起使用,以便我可以通过 Netlify 进行部署。这是我尝试 运行 next export

时遇到的错误示例
Error occurred prerendering page "/videos/[videos_title]". Read more: https://err.sh/next.js/prerender-error:
Error: Error for page /videos/[videos_title]: pages with `getServerSideProps` can not be exported. See more info here: https://err.sh/next.js/gssp-export

使用 SSR 构建的应用程序不能部署在 Netlify 或任何其他静态托管站点(Vercel 除外,它支持 NextJS SSR 部署)

When you go for SSR (using getServerSideProps), it's meaningless to use the command next export since it will try to create static content which is totally opposite to the SSR.

  • 一种部署方式是 运行 在虚拟服务器中(如 EC2) 通过使用正确的路由配置创建自定义 server.js 文件。
  • 另一种简单快捷的方法是使用 Vercel (Zeit 以前) 用于部署 SSR 实现的应用程序,其中 他们处理得很明智

Vercel 的 SSR 应用程序部署文档很差。幸运的是,我从支持团队那里得到了以下信息,并要求他们更新文档以详细说明 Vercel 中的 SSR 部署。

When deploying in Vercel,

  • 将生成命令作为 next buildnpm run build
  • 将输出目录保留为

注意:具有自定义 server.js 的应用程序在 Vercel 中无法正常工作,在这种情况下,请选择虚拟服务器(如 EC2)