gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 16:21:36 25 4
gpt4 key购买 nike

我一直致力于实现来自 Next 9.3 的一些更新。 .我一直在搬家getInitialPropsgetServerSideProps并注意到我的 exportPathMap对这些页面变得动态变得不满意。运行一切正常 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.我能够让它与我的新 getServerSideProps 一起愉快地工作运行时调用 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 或任何其他静态托管站点(除了支持 NextJS SSR 部署的 Vercel)

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 (时代
    以前)
    用于部署 SSR 实现的应用程序,其中
    他们明智地处理它

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

    When deploying in Vercel,


  • 将构建命令指定为 next buildnpm run build
  • 将输出目录保留为

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

    关于next.js - 如何使用 Next.js 自动静态站点优化并仍然为 Netlify 导出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61379200/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com