Next.js is an open-source React framework designed for building performant and scalable web applications. It supports a variety of rendering strategies, including Server-Side Rendering (SSR), Static Site Generation (SSG), Incremental Static Regeneration (ISR), and client-side rendering. The current stable version is 16.2.4. Next.js typically releases new features and major architectural changes, like the App Router and React Server Components, in frequent canary and beta channels, with stable versions receiving backported bug fixes and optimizations. Key differentiators include its file-system-based routing, built-in image and font optimization, API routes for backend functionality, and deep integration with React Server Components for a full-stack development experience. It aims to provide a complete solution for React applications, abstracting much of the build configuration and deployment complexities.
npm install nextVerified import paths — ran on the pinned version, not inferred.
Demonstrates a basic Next.js App Router setup with a homepage, an about page with client-side navigation using `Link`, and a simple API Route Handler (`app/api/hello/route.ts`) to fetch dynamic data.
For new projects, use `npx create-next-app@latest --app`. For existing projects, consider a gradual migration using the `next/compat/router` or maintain the Pages Router, understanding that new features will primarily target the App Router.
Update `compilerOptions.moduleResolution` in your `tsconfig.json` to `"bundler"` (recommended for Next.js) or `"nodenext"`.
Prefix client-accessible environment variables with `NEXT_PUBLIC_`. For server-only variables, ensure they are only accessed in server-side contexts like API routes, `getServerSideProps` (Pages Router), or Server Components/Route Handlers (App Router).
For remote images, add entries to `images.remotePatterns` in `next.config.js` matching the hostname of your image provider. For static exports, either use a custom image loader, set `unoptimized={true}` on the `Image` component, or use a standard `<img>` tag.Move browser-only API calls into `useEffect` hooks, ensure dynamic content is handled client-side or synchronized, and verify correct HTML nesting. The `suppressHydrationWarning={true}` prop can be used as an escape hatch for unavoidable mismatches, but should be used sparingly.Identify the differing content. Use `useEffect` for client-side only rendering, ensure consistent data across environments, or use `suppressHydrationWarning` on the offending element as a last resort.
Add the image hostname (e.g., `example.com`) to the `images.remotePatterns` array in your `next.config.js` file.
Ensure `useRouter` is called inside a client component (marked with `'use client'`) and imported from the correct path: `next/navigation` for App Router or `next/router` for Pages Router.
Add a `export default function MyPage() { ... }` (or an equivalent default export) to the page file.Refactor the component to avoid server-only dependencies on the client, use dynamic imports with `ssr: false`, or ensure the component is a Server Component and its dependencies are also compatible with the server environment.