Deploy a Next.js SPA on AWS

You can deploy a Next.js SPA site on AWS with Thunder. The server pre-rendered pages produced by the build step will be stored in an S3 bucket and served using CloudFront CDN.

View code in StackBlitz

Configure

In next.config.mjs file, uncomment the line that sets output: "export". Learn more about Next.js static exports.

next.config.mjs
/** @type {import('next').NextConfig} */
const nextConfig = {
output: "export", // for SPA mode
reactStrictMode: true,
swcMinify: true,
eslint: {
ignoreDuringBuilds: true,
},
typescript: {
ignoreBuildErrors: true,
},
images: {
unoptimized: true,
},
experimental: {
webpackBuildWorker: true,
parallelServerBuildTraces: true,
parallelServerCompiles: true,
},
}
export default nextConfig

Build Settings

Use the following commands in the build step settings:

Install command
npm install --legacy-peer-deps
Build command
npm run build
Output directory
out

That’s it! Your app will be live on your CloudFront URL as soon as the build finishes.