LaunchPad guides

How to Deploy a Next.js Static Site for Free

Hostmargin · · 3 min read
How to Deploy a Next.js Static Site for Free

Next.js can build your whole site into plain HTML, CSS and JavaScript files, called a static export. Those files can be hosted for free on LaunchPad, with free SSL and a deploy on every push. This guide shows how to deploy a Next.js static site for free, and which Next.js features need a server and won't work.

Is static export right for your app?

Static export suits marketing sites, blogs, documentation, portfolios and most apps that fetch data in the browser. It doesn't support features that need a running server:

  • API routes and route handlers that run on request
  • Middleware
  • getServerSideProps and incremental static regeneration (ISR)
  • The built-in image optimizer (fixed below with one setting)

Pages built at build time, client-side data fetching and the App Router's static pages all work.

Step 1: Enable static export

Add output: 'export' to next.config.js, and turn off image optimization:

// next.config.js
/** @type {import('next').NextConfig} */
module.exports = {
  output: 'export',
  images: { unoptimized: true },
  trailingSlash: true, // optional: /about becomes /about/index.html
}

Run npm run build locally. Next.js writes the site to the out folder. If the build complains about a feature, it's one from the list above.

Step 2: Push and create the project

  1. Commit and push to GitHub or GitLab.
  2. Sign in at launchpad.hostmargin.com, click New project and paste the repository URL and branch.
  3. Choose the Next.js (static) preset:
Setting Value
Build command npm run build
Output directory out

Step 3: Choose an address and deploy

Pick a free subdomain and click Create & Deploy. You can watch every step of the build in the live log. Once it shows Live, open your address: it's already on HTTPS.

Step 4: Deploy on every push

Add the webhook URL and secret from the project's Settings tab to your repository. From then on, each push to your branch builds a new release. The switch to the new version happens only after the build succeeds, so visitors never see a half-finished site.

Common problems

"Image Optimization using the default loader is not compatible with export"

Add images: { unoptimized: true } as shown above, or use a third-party image loader.

Links to /about show a 404

Set trailingSlash: true so each page is written as a folder with an index.html. Links then work with or without the slash.

"Output directory not found"

The build didn't produce out, usually because output: 'export' is missing from next.config.js. Check the build log: the last lines show where Next.js wrote the files.

The build is slow or runs out of time

Large sites with thousands of pages take longer. Check the build log for the slow step; your plan's build timeout is listed on the FAQ.

Next steps

Ship your next site today

Three projects free, forever. Sign in with your Hostmargin account — no credit card required.