# Deploy Next.js on forkrail

> Next.js 13.5 through 16 (App Router and Pages Router) builds without changing `next.config`, sharing one router-backed cache for ISR, RSC, and `revalidateTag`, plus router-served `/_next/image`.

- Framework: Next.js
- Category: Websites & full-stack
- Status: Beta
- Adapter / Preset: Automatic standalone + forkrail adapter (Next 15.5+)
- Runtime: Node.js 24 or 22 (arm64) · Static S3 for output: export
- Detection: package.json (next)
- Memory: 1,024–2,048 MB recommended
- URL: https://www.forkrail.com/frameworks/nextjs

## Capabilities

| Capability | Support | Details |
| --- | --- | --- |
| App & Pages Router | Supported | Next.js 13.5–16 SSR, streaming, Server Actions, Draft Mode |
| Shared router cache | Supported | ISR, fetch/use cache, revalidatePath & revalidateTag across workers |
| Image optimization | Supported | /_next/image handled by router with next.config image settings |
| Beta status | Partial | Works for previews & testing; 250 MB unzipped Lambda package limit |

## Honest beta status

> **Private beta for Next.js:** Next.js 13.5–16 builds, runs, shares a router-backed cache across workers, and persists `.next/cache` between builds. Conformance testing against Next.js’s upstream suite and container-image packaging for >250 MB apps are still underway — test thoroughly on preview URLs before moving critical production apps.

## 1. Zero changes to next.config

You do not need to edit `next.config` or add custom cache handlers. During the build, forkrail enables standalone output automatically (via `NEXT_ADAPTER_PATH` on Next 15.5+ or `NEXT_PRIVATE_STANDALONE=1`), seeds prerendered pages and RSC payloads directly into the router’s shared cache, and preserves `.next/cache` (including Turbopack/webpack caches and Server Actions encryption keys) for fast rebuilds.

If your config sets `output: 'export'`, forkrail leaves it alone and deploys the exported `out/` directory as a zero-Lambda static site while honoring `redirects()`, `rewrites()`, `headers()`, and `basePath`.

## 2. Deploy a Next.js preview

**Deploy and verify your Next.js app**

```bash
# Allocate generous memory for fast Next.js cold starts and SSR
forkrail project my-next-app --memory 1536

# Deploy a preview URL and test side by side
forkrail deploy

# Check logs and cache hits (x-vercel-cache: HIT / STALE / MISS)
forkrail logs my-next-app --app --follow
```

## 3. Current limits & tips

- **Supported versions:** Next.js 13.5 and later on Node 22 or 24 (set via `engines.node`). Next before 13.5 and Yarn Plug’n’Play (`nodeLinker: pnp`) are refused.
- **Package size limit:** Standalone output must stay under AWS Lambda’s 250 MB unzipped limit (the build log breaks down `node_modules` and largest files if exceeded).
- **Middleware matchers:** Exclude `_next/static` and static image paths from your `middleware.ts` matcher so the router serves static files and cached pages without waking Node.
- **Skew protection:** Works automatically on Next 14.1.4+ (and 13.5–14.1.3 with `experimental.useDeploymentId`).

## Related documentation

- [Moving from Vercel](https://www.forkrail.com/docs/moving-from-vercel.md)
- [Image optimization](https://www.forkrail.com/docs/image-optimization.md)
- [Logs & observability](https://www.forkrail.com/docs/logs-and-observability.md)
