next.js

Framework

vercel/next.js

Full-stack React framework for production-grade web applications.

Overview

Next.js extends React with server-side rendering, static generation, and hybrid capabilities. It provides file-system routing, API routes, and optimized builds using Rust-based tooling. Used by major companies for fast, scalable web apps.

README Preview

\n  \n    \n      \n      \n    \n  \n  Next.js\n\n\n\n\n\n\n\n\n## Getting Started\n\nUsed by some of the world's largest companies, Next.js enables you to create full-stack web applications by extending the latest React features, and integrating powerful Rust-based JavaScript tooling for the fastest builds.\n\n- Visit our [Learn Next.js](https://nextjs.org/learn) course to get started with Next.js.\n- Visit the [Next.js Showcase](https://nextjs.org/showcase) to see more sites built with Next.js.\n\n## Documentation\n\nVisit [https://nextjs.org/docs](https://nextjs.org/docs) to view the full documentation.\n\n## Community\n\nThe Next.js community can be found on [GitHub Discussions](https://github.com/vercel/next.js/discussions) where you can ask questions, voice ideas, and share your projects with other people.\n\nTo chat with other community members you can join the Next.js [Discord](https://nextjs.org/discord) server.\n\nDo note that our [Code of Conduct](https://github.com/vercel/next.js/blob/canary/CODE_OF_CONDUCT.md) applies to all Next.js community channels. Users are **highly encouraged** to read and adhere to it to avoid repercussions.\n\n## Contributing\n\nContributions to Next.js are welcome and highly appreciated. However, before you jump right into it, we would like you to review our [Contribution Guidelines](/contributing.md) to make sure you have a smooth experience contributing to Next.js.\n\n### Good First Issues:\n\nWe have a list of **[good first issues](https://github.com/vercel/next.js/labels/good%20first%20issue)** that contain bugs that have a relatively limited scope. This is a great place for newcomers and beginners alike to get started, gain experience, and get familiar with our contribution process.\n\n---\n## Security\n\nIf you believe you have found a security vulnerability in Next.js, we encourage you to **_responsibly disclose this and NOT open a public issue_**.\n\nTo participate in our Open Source Software Bug Bounty program, please

FAQ (5)

Troubleshooting
How to fix database connection exhaustion caused by Fast Refresh (hot reloading) in Next.js 13 app directory?

In dev mode, Next.js Fast Refresh re-evaluates modules on every save, so a top-level new DatabaseConnection(...) (or postgres(), PrismaClient, etc.) creates a new connection each time until PostgreSQL fails with remaining connection slots are reserved for non-replication superuser connections. Fix it by caching the client on globalThis so the connection survives reloads:

import postgres from 'postgres';

declare module globalThis {
  let postgresSqlClient: ReturnType<typeof postgres> | undefined;
}

function connectOnceToDatabase() {
  if (!globalThis.postgresSqlClient) globalThis.postgresSqlClient = postgres();
  return globalThis.postgresSqlClient;
}

export const sql = connectOnceToDatabase();

The same singleton pattern works for Prisma (globalThis.prisma ??= new PrismaClient()) and other drivers. This only affects development; production builds don't re-evaluate modules per request.

GitHub Issue #45483
Troubleshooting
How do I fix the Turbopack "module factory is not available" hydration error in a Next.js Pages Router app after upgrading to 16.4?

This is a known Turbopack dev regression introduced by #97664 in Next.js 16.4.0. Page modules can be omitted from client chunks when the page chunk group reuses _app availability data, causing SSR to succeed but hydration to fail with module factory is not available.

Permanent fix: upgrade to a Next.js canary/preview release containing PR #98823, which chains the Pages Router development client module graph. The fix was verified with next@16.5.0-preview-358550b2-20261009.

npm install next@canary
rm -rf .next
npm run dev

If you cannot upgrade, use one of these workarounds:

# Downgrade to the last unaffected release
npm install next@16.3.8
rm -rf .next
npm run dev

Or run development with webpack instead of Turbopack:

npx next dev --webpack -p 3456

Production builds are not affected, so next build && next start also works on 16.4.0.

GitHub Issue #99789
Troubleshooting
Why does Next.js 16.4 fail to hydrate with a nonce-based CSP when using Turbopack and cacheComponents?

Next.js 16.4 enables experimental.turbopackSharedRuntime by default. With cacheComponents: true, Turbopack inlines its chunk-group bootstrap into the prerendered shell without adding the request nonce. A strict CSP such as script-src 'self' 'nonce-<random>' blocks that inline <script id="_R_">, so the client runtime never starts and hydration fails.

Workaround: disable the shared runtime in next.config.js:

module.exports = {
  experimental: {
    turbopackSharedRuntime: false,
  },
};

Then rebuild and restart:

next build && next start

This restores the previous behavior where the bootstrap is loaded as an external script allowed by 'self'. The issue affects Next.js 16.4.0 with Turbopack, React 19.2, and cacheComponents: true; using a script hash is impractical because the bootstrap changes per route and build.

GitHub Issue #99799
Troubleshooting
How do I fix Next.js standalone output on Windows creating symlinks that point outside `.next/standalone`?

Upgrade Next.js to **16.4.0 or later**, where this Windows symlink issue was fixed:

pnpm add next@^16.4.0
# or
yarn add next@^16.4.0

Then remove the old build output and rebuild:

rm -r .next
pnpm build

The generated symlinks under .next/standalone/node_modules should now resolve within .next/standalone/node_modules/.pnpm instead of the build machine’s root node_modules or absolute Windows paths. The bug was reproduced with Next.js 16.2.10 and 16.3.0 on Windows with pnpm, and similar absolute-symlink behavior was reported with yarn. If upgrading is not immediately possible, a reported workaround is to build the standalone output on Linux or use webpack for local Windows container builds.

GitHub Issue #95450
Troubleshooting
How do I prevent `next build` from deleting monorepo files when `distDir` points outside the Next.js app?

Next.js clears distDir before building. With distDir: "../../" in apps/web, the resolved path is the monorepo root, so Next.js recursively deletes that directory. Keep distDir inside the Next.js project root:

1. Edit apps/web/next.config.ts and remove the unsafe setting or use a local directory:

const nextConfig = {
  distDir: '.next',
}

2. Do not point distDir at the repository root, home directory, /, or another project.
3. For Vercel monorepo deployments, go to **Project Settings → General → Root Directory** and set it to apps/web instead of moving .next to the repository root. Vercel will then detect the build output automatically.
4. Verify the resolved path before building from apps/web:
node -e "console.log(require('path').resolve('../../'))"

If it prints the monorepo root or another directory containing unrelated files, the configuration is unsafe.
5. Upgrade from Next.js 16.3.5 to a newer release containing the custom distDir safety validation.

The deletion is permanent and does not use the system trash; restore affected files from Git or another backup.

GitHub Issue #98958