Next.js Discord

Discord Forum

Incrementally Migrating to Next.js from a static react app with no dependency on a nodejs server

Answered
Leafcutting bee posted this in #help-forum
Open in Discord
Leafcutting beeOP
I'm working on migration of an existing react app that hosts static files in S3 and utilizes CloudFront to serve the assets. My first requirement is to get everything working with the nextjs build scripts without modifying our deployment. I realize most of the benefits of Nextjs come from serving pre-rendered content via server but I'd like to get things working as is first before making additional changes.

Can I achieve this by using app routing and client components with a static export to S3 or will I still require a nodejs server to serve the app (or serverless functions)?
Answered by Rafael Almeida
you can use the static export to build static files that can be served from S3 or any other CDN: https://nextjs.org/docs/app/building-your-application/deploying/static-exports
View full answer

7 Replies

you can use the static export to build static files that can be served from S3 or any other CDN: https://nextjs.org/docs/app/building-your-application/deploying/static-exports
Answer
keep in mind this still pre-render the pages, if your app doesn't work at all with pre-rendering, you can disable the components with a dynamic import: https://nextjs.org/docs/app/building-your-application/optimizing/lazy-loading#skipping-ssr
Leafcutting beeOP
Thanks @Rafael Almeida – what happens to server components when we use static export vs a client component?
both types of components are pre-rendered too
Leafcutting beeOP
besides testing manually – do you know how I might identify what parts of my react app wont work with pre-rendering?
anything that tries to uses features from the browser in the server during rendering. like reading window for the initial state. e.g.:
function Foo() {
  useState(window.localStorage....)
}
Leafcutting beeOP
ahh that makes sense