Skip to content
Latchkey

Next.js standalone output missing static and public files in CI

With output: 'standalone', next build produces a minimal .next/standalone server that does not include .next/static or public. If your image or artifact omits those, the server starts but assets 404 or the route fails.

What this error means

The standalone server runs but pages render unstyled, scripts 404, or images under /public are missing, because only .next/standalone was copied without .next/static and public.

next build
# Dockerfile copying only the standalone server
COPY --from=builder /app/.next/standalone ./
# missing: .next/static and public -> assets 404 at runtime

Common causes

standalone intentionally excludes static and public

The standalone trace copies only server dependencies; .next/static and public are separate and must be added by you.

A Dockerfile or artifact copies only the server

A COPY that grabs .next/standalone alone leaves the browser assets behind.

How to fix it

Copy static and public alongside the server

  1. Copy .next/standalone as the app root.
  2. Copy .next/static into .next/static of the standalone tree.
  3. Copy public into the standalone tree, then run node server.js.
Dockerfile
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
COPY --from=builder /app/public ./public

Enable standalone output deliberately

Confirm the config opts in, so the standalone folder is produced.

next.config.js
// next.config.js
module.exports = { output: 'standalone' }

How to prevent it

  • Always copy .next/static and public with the standalone server.
  • Test the produced image serves CSS, JS, and public assets.
  • Keep the COPY steps in sync when the output mode changes.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →