|
1 | 1 | import { SITE } from "../../config";
|
2 | 2 | import { Callout } from "nextra/components";
|
3 | 3 |
|
4 |
| -## Netlify |
| 4 | +# Next.js on Netlify |
5 | 5 |
|
6 |
| -TODO |
| 6 | +<a href="https://runtime-e2e-report.netlify.app/" target="_blank"> |
| 7 | + <img |
| 8 | + src="https://runtime-e2e-report.netlify.app/badge" |
| 9 | + width="185" |
| 10 | + height="25" |
| 11 | + style={{ borderRadius: 0, marginTop: "1rem" }} |
| 12 | + alt="Netlify Next.js runtime v5 test status" |
| 13 | + /> |
| 14 | +</a> |
| 15 | + |
| 16 | +Netlify's Next.js runtime automatically configures Netlify sites with key functionality, including cache control, on-demand revalidation, and image optimization. |
| 17 | + |
| 18 | +The runtime provisions serverless and edge functions as appropriate to handle your site’s server-side functionality (such as SSR, ISR and PPR pages, API endpoints, Server Actions, Edge Middleware, etc.), ensuring that functionality works out-of-the-box. |
| 19 | + |
| 20 | +We automatically verify compatibility with the latest stable version of Next.js, using the comprehensive end-to-end tests of the framework itself. To access up-to-date test results, use the badge above. |
| 21 | + |
| 22 | +## Get started |
| 23 | + |
| 24 | +The easiest way to get started is to deploy our Next.js platform starter template to your Netlify account. Use the button below to get started. |
| 25 | + |
| 26 | +[](https://app.netlify.com/start/deploy?repository=https://github.com/netlify-templates/next-platform-starter) |
| 27 | + |
| 28 | +### Prerequisites |
| 29 | + |
| 30 | +- Next.js version 13.5 and later (up to the latest stable version) |
| 31 | +- [Node 18.x or later](https://docs.netlify.com/configure-builds/manage-dependencies/#node-js-and-javascript) |
| 32 | +- The latest version of [Netlify CLI](https://docs.netlify.com/cli/get-started/) |
| 33 | + |
| 34 | +## Key features |
| 35 | + |
| 36 | +- **App Router:** Netlify fully supports the Next.js App Router, which supports more powerful nested layouts and React’s latest features, such as Server Components and Streaming. |
| 37 | + |
| 38 | +- **Automatic fine-grained caching:** Next.js Runtime v5 uses fine-grained caching on Netlify to support the Next.js Full Route Cache and Data Cache. This means that static page responses are automatically cached at the edge and can be revalidated by path or by tag. |
| 39 | + |
| 40 | +- **On-demand and time-based revalidation:** Both the App Router and Pages Router support on-demand and time-based revalidation, allowing you to revalidate and regenerate content at any time after a deploy. |
| 41 | + |
| 42 | +- **Image optimization:** The `next/image` component uses [Netlify Image CDN](https://docs.netlify.com/image-cdn/overview/) by default to ensure your images are optimized and served in the most efficient format. |
| 43 | + |
| 44 | +Note that while we also generally support experimental features (for example, Partial Prerendering) from their early stages, such features are not considered stable yet at the framework level. |
| 45 | + |
| 46 | +## Automatic runtime detection |
| 47 | + |
| 48 | +Netlify automatically detects that you're using Next.js and provisions your site with the most up-to-date runtime. |
| 49 | + |
| 50 | +### Pin a specific runtime version |
| 51 | + |
| 52 | +To pin the Netlify Next.js runtime to a specific version, read [the Netlify docs](https://docs.netlify.com/frameworks/next-js/overview/). |
| 53 | + |
| 54 | +### Suggested configuration values |
| 55 | + |
| 56 | +When you [link a repository](https://docs.netlify.com/welcome/add-new-site/#import-from-an-existing-repository) for a Next.js project, Netlify provides a suggested build command and publish directory: `next build` and `.next`. |
| 57 | + |
| 58 | +If you’re using the CLI to run [Netlify Dev](https://docs.netlify.com/cli/local-development/) for a local development environment, Netlify suggests a dev command and port: `next` and `3000`. |
| 59 | + |
| 60 | +You can override suggested values or set them in a configuration file instead, but suggested values from automatic framework detection may help simplify the process of setting up a Next.js site on Netlify. |
| 61 | + |
| 62 | +For manual configuration, check out the [typical build settings](https://docs.netlify.com/frameworks/#next-js) for Next.js. |
| 63 | + |
| 64 | +## Limitations |
| 65 | + |
| 66 | +Currently, Netlify's Next.js runtime has the following limitations: |
| 67 | + |
| 68 | +- **SSR pages set to the `edge` runtime will run in your [functions region](https://docs.netlify.com/functions/optional-configuration/#region).** If edge-level performance is critical, we advise that you use static pages with edge functions instead. They are rendered at the origin, but are then cached at the edge and can be revalidated on demand. |
| 69 | + |
| 70 | +- **Rewrites in your Next.js configuration can’t point to static files in the `public` directory.** If you create `beforeFiles` rewrites in your `next.config.js`, they can’t point to static files in your site’s `public` directory. You can use middleware rewrites as an alternative. |
| 71 | + |
| 72 | +- **Netlify Forms compatibility:** Using Netlify Forms with the current runtime [requires a workaround](/netlify/forms). |
| 73 | + |
| 74 | +### pnpm support |
| 75 | + |
| 76 | +If you’re planning to use pnpm with Next.js to manage dependencies, you must do one of the following: |
| 77 | + |
| 78 | +- Set a `PNPM_FLAGS` [environment variable](https://docs.netlify.com/environment-variables/get-started/#create-environment-variables) with a value of `--shamefully-hoist`. This appends a `--shamefully-hoist` argument to the `pnpm install` command that Netlify runs. |
| 79 | +- [Enable public hoisting](https://pnpm.io/npmrc#public-hoist-pattern) by adding an `.npmrc` file in the root of your project with this content: |
| 80 | + |
| 81 | + ```bash |
| 82 | + public-hoist-pattern[]=* |
| 83 | + ``` |
| 84 | + |
| 85 | +Learn more about using [pnpm on Netlify](https://docs.netlify.com/configure-builds/manage-dependencies/#pnpm). |
| 86 | + |
| 87 | +## Troubleshooting |
| 88 | + |
| 89 | +The OpenNext docs are specifically about using Netlify's Next.js runtime v5.8 and later. For older versions of the runtime, refer to the [Netlify docs](https://docs.netlify.com/frameworks/next-js/overview/). |
| 90 | + |
| 91 | +If you need help with any version of the runtime, visit [our support page](https://www.netlify.com/support) for various methods of finding answers and getting help. |
| 92 | + |
| 93 | +### More resources |
| 94 | + |
| 95 | +- [Typical Next.js build settings](https://docs.netlify.com/frameworks/#next-js) |
| 96 | +- [Next.js framework documentation](https://nextjs.org/docs/getting-started) |
| 97 | +- [Connect JavaScript client](https://docs.netlify.com/connect/access-data/#use-the-connect-client) - the recommended library for querying Connect data layer APIs in Next.js cached SSR sites. |
0 commit comments