Menu

Building for Production

Lesson 1: Building for Production

What does a production build do?

next build turns your source code into an optimised application:

Step Result
Compile with Turbopack Minified JavaScript and CSS, split by route
Type-check Build fails on TypeScript errors
Prerender Static pages and static shells written to .next
Collect route info Table of routes with their rendering mode and size

Since Next.js 16, linting is no longer part of next build. Run ESLint or Biome as a separate CI step.

Example

npm run build
npm run start   # Serves on http://localhost:3000

A simple CI pipeline (GitHub Actions):

# .github/workflows/ci.yml
name: CI
on: [push, pull_request]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 22
          cache: npm
      - run: npm ci
      - run: npm run lint
      - run: npx vitest run
      - run: npm run build

How it works

  • The .next folder contains everything next start needs.
  • Environment variables are read at build time for NEXT_PUBLIC_ values (inlined into JavaScript) and at runtime for server-only values.
  • Since 16.3, Turbopack can reuse cached build artifacts, so repeat builds on CI are faster when the cache is preserved.

Common mistakes

Mistake Effect Fix
Changing a NEXT_PUBLIC_ value without rebuilding Old value still in the browser Rebuild after changing public variables
Skipping lint and tests because the build passes Bugs ship Run lint, tests, and build in CI
Running next dev in production Slow, insecure, memory-hungry Always use next build + next start

Key takeaways

  • next build compiles, type-checks, and prerenders; next start serves the result.
  • Automate lint, tests, and build on every push.

Try it: Add the CI workflow above to LearnHub and make a commit that fails type-checking to see the pipeline catch it.


Nextjs Tutorial

J

Jebasta





Get in Touch For Details