Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,93 @@ You can find more detailed examples in the [Azion Bundler repository](https://gi

---

## OpenNext

The [`@aziontech/opennextjs-azion`](https://www.npmjs.com/package/@aziontech/opennextjs-azion) adapter lets you deploy Next.js apps to [Azion Functions](https://www.azion.com/en/products/edge-functions/) using the [Node.js "runtime" from Next.js](https://nextjs.org/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes).

### Get Started

##### New apps

To create a new Next.js app, pre-configured to run on Azion using `@aziontech/opennextjs-azion`, run:

```shell
npx create-next-app@14.2.4 my-next-app --use-npm && cd my-next-app && npm install @aziontech/opennextjs-azion@latest
```

##### Existing Next.js apps

[Follow the guide here](/azion/get-started) to use [@aziontech/opennextjs-azion](https://www.npmjs.com/package/@aziontech/opennextjs-azion) with an existing Next.js app.

### Supported Next.js versions

All minor and patch versions of Next.js 15 and the latest minor of Next.js 14 are supported.

To help improve compatibility, we encourage you to [report bugs](https://github.com/aziontech/opennextjs-azion/issues) and contribute code!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
To help improve compatibility, we encourage you to [report bugs](https://github.com/aziontech/opennextjs-azion/issues) and contribute code!
To help improve compatibility, we encourage you to [report bugs](https://github.com/aziontech/opennextjs-azion/issues) and contribute with code!


### Supported Next.js features

| Feature | Support | Comments |
|---|---|---|
| [App Router](https://nextjs.org/docs/app) | 🟢 | |
| [Route Handlers](https://nextjs.org/docs/app/building-your-application/routing/route-handlers) | 🟢 | |
| [Dynamic routes](https://nextjs.org/docs/app/building-your-application/routing/dynamic-routes) | 🟢 | |
| [Static Site Generation (SSG)](https://nextjs.org/docs/app/building-your-application/rendering/server-components#static-rendering-default) | 🟢 | |
| [Server-Side Rendering (SSR)](https://nextjs.org/docs/app/building-your-application/rendering/server-components) | 🟢 | |
| [Middleware](https://nextjs.org/docs/app/building-your-application/routing/middleware) | 🟢 | |
| [Node Middleware](https://nextjs.org/docs/app/building-your-application/routing/middleware#runtime) | 🟡 | introduced in 15.2 are not yet supported |
| [Image Optimization](https://nextjs.org/docs/app/building-your-application/optimizing/images) | 🔴 | |
| [Partial Prerendering (PPR)](https://nextjs.org/docs/app/building-your-application/rendering/partial-prerendering) | 🟢 | |
| [Pages Router](https://nextjs.org/docs/pages) | 🟢 | |
| [Incremental Static Regeneration (ISR)](https://nextjs.org/docs/app/building-your-application/data-fetching/incremental-static-regeneration) | 🟢 | |
| [Support for after](https://nextjs.org/blog/next-15-rc#executing-code-after-a-response-with-nextafter-experimental) | 🟢 | |
| [Composable Caching](https://nextjs.org/blog/composable-caching) | 🔴 | ('use cache') |

:::note
Azion Functions have a maximum size limit of 50 MB per function. After building your project, pay attention to the compressed (gzipped) size of your deployment package—only the compressed size counts toward this limit.
For more details, see the [documentation on Function size limits](/en/documentation/products/build/edge-application/edge-functions/#limits).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
For more details, see the [documentation on Function size limits](/en/documentation/products/build/edge-application/edge-functions/#limits).
For more details, see the [documentation on Functions size limits](/en/documentation/products/build/edge-application/edge-functions/#limits).

:::

### Examples

To create a new Next.js app for Azion, you can use the following starter projects and templates:

#### Basic starter projects

- [Next.js + TypeScript + Tailwind Template](https://github.com/aziontech/azion-samples/tree/dev/templates/opennextjs/nextal-next-typescript-tailwind) — a ready-to-use template for building modern Next.js apps on Azion Functions.
- [Node Playground (Next.js 13)](https://github.com/aziontech/bundler-examples/tree/main/examples/nextjs/node-playground-13) — an example showing how to run Next.js 13 in a Node.js environment on Azion.

You can use these repositories to understand how to configure your Next.js app to run on Azion, or as a starting point for your own projects.

### Known issues

#### TS Config
- Your `tsconfig.json` must include the following setting:

```json
"moduleResolution": "bundler"
```

If this is not set, you may encounter issues during the build or runtime process.

- There is a known issue with ESM and the `open-next.config.ts` file. If you have an older project or one that depends on a specific TypeScript version or custom configuration, you may need to:
- Reconfigure your project (for example, by setting `moduleResolution: bundler` as above), **or**
- Add the following to your `tsconfig.json`:

```json
"exclude": ["node_modules", "open-next.config.ts"]
```

Whether this works depends on your project setup. In some cases, excluding `open-next.config.ts` allows the build to proceed, but you may still encounter errors, especially if your project uses features like `_app.mdx` or other advanced configurations. This is particularly relevant for projects that haven't been tested with these setups, and issues may also occur in other environments (such as the Cloudflare package).

#### Local Development

- Some applications may use Node.js or Web Standard APIs that are not fully supported by Azion's local development environment. However, these features might be available in the actual Azion runtime.

:::tip
If your application does not work as expected during local development, try deploying it to Azion before troubleshooting further, as it may work correctly in the deployed environment.
:::

## Next.js 14.x.y

| Feature | Support | Comments |
Expand All @@ -37,7 +124,7 @@ You can find more detailed examples in the [Azion Bundler repository](https://gi
| Static Pages | 🟢 | |
| SSR | 🟢 | |
| SSG | 🟢 | |
| Edge API Routes | 🟢 | |
| API Routes | 🟢 | |
| Dynamic Routes | 🟢 | |
| Middleware | 🟡 | Features: rewrite, redirect, continue to response, set request header, throw error, set response header, and set response cookie|
| Next configs | 🟡 | Features: rewrite before files, rewrite after files, rewrite fallback, redirects, and header definition |
Expand All @@ -50,7 +137,7 @@ You can find more detailed examples in the [Azion Bundler repository](https://gi
| Static Pages | 🟢 |
| SSR | 🟢 | |
| SSG | 🟢 | |
| Edge API Routes | 🟢 | |
| API Routes | 🟢 | |
| Dynamic Routes | 🟢 | |
| Middleware | 🟡 | Features: rewrite, redirect, continue to response, set request header, throw error, return response, set response header, and set response cookie |
| Next configs | 🟡 | Features: rewrite before files, rewrite after files, rewrite fallback, redirects, and header definition |
Expand Down
182 changes: 182 additions & 0 deletions src/content/docs/en/pages/guides/open-next/get-started-opennext.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
---
title: Get Started With OpenNext
description: >-
Get started with OpenNext on Azion: create or adapt a Next.js app, configure caching and storage for ISR/SSG, develop locally with the Azion CLI, and deploy to production.
permalink: /documentation/products/guides/opennext/get-started/
meta_tags: >-
Next.js compatibility, Azion Web Platform, SSR, SSG, Middleware Features,
Static Generation, Server-side Rendering, Next.js Routing, Next.js
Performance, Next.js Integrations
namespace: documentation_guides_opennext_get_started
---

The `@aziontech/opennextjs-azion` adapter lets you deploy Next.js apps to Azion Web Platform. This guide will help you set up a new or existing Next.js project for Azion, configure caching, develop locally, and deploy to production.

---

### Prerequisites

- [CLI Installed](/en/documentation/products/azion-cli/overview/#installing-azion-cli).

---

#### Creating a New Next.js App

To create a new Next.js app pre-configured for Azion:

```sh
npx create-next-app@14.2.4 my-next-app --use-npm
cd my-next-app
npm install @aziontech/opennextjs-azion@latest
```

Or use a starter template:

- [Next.js + TypeScript + Tailwind Template](https://github.com/aziontech/azion-samples/tree/dev/templates/opennextjs/nextal-next-typescript-tailwind)
- [Node Playground (Next.js 13)](https://github.com/aziontech/bundler-examples/tree/main/examples/nextjs/node-playground-13)

---

#### Existing Next.js Apps

1. Install the Azion Adapter:

```sh
npm install @aziontech/opennextjs-azion@latest
```

2. Configure `open-next.config.ts`:

Create or update `open-next.config.ts` in your project root. Example:

```ts
import { defineAzionConfig } from "@aziontech/opennextjs-azion";

export default defineAzionConfig({
// See /azion/caching for advanced options
});
```

3. Update `tsconfig.json`:

:::warning
Your `tsconfig.json` must include: ```json "moduleResolution": "bundler" ```. This is required for correct build and runtime behavior.
:::

If you encounter issues with ESM or `open-next.config.ts`, you may need to add:

```json
"exclude": ["node_modules", "open-next.config.ts"]
```

See [Known Issues](/en/documentation/devtools/azion-edge-runtime/compatibility/nextjs/#known-issues) for more details.

1. Azion CLI Build and Deploy:

- `azion build`: Builds your app for Azion.
- `azion preview`: Runs a local preview using Azion CLI.
- `azion deploy`: Deploys to Azion Web Platform using Remote Deployment.
- or `azion deploy --local` to deploy to Azion Web Platform using Local Deployment.

5. Set Up Caching and Storage:

Example Azion config:

```ts
AzionCache
Type definition for the cache configuration.
```

Properties:

| Property | Type | Description |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Esses ? estão corretos aqui?

| --- | --- | --- |
| name | string | Name of the cache configuration. |
| stale? | boolean | Whether to allow stale content. |
| queryStringSort? | boolean | Whether to sort query string parameters. |
| methods? | CacheMethods | HTTP methods to cache. |
| post? | boolean | Whether to cache POST requests. |
| options? | boolean | Whether to cache OPTIONS requests. |
| browser? | BrowserCacheConfig | Browser cache settings. |
| browser.maxAgeSeconds | number \| string | Maximum age for browser cache in seconds. |
| edge? | EdgeCacheConfig | Cache settings. |
| edge.maxAgeSeconds | number \| string | Maximum age for cache in seconds. |
| cacheByCookie? | CacheByCookieConfig | Cache by cookie settings. |
| cacheByCookie.option | 'ignore' \| 'varies' \| 'whitelist' \| 'blacklist' | Cache by cookie option. |
| cacheByCookie.list? | string[] | List of cookies to use for caching. |
| cacheByQueryString? | CacheByQueryStringConfig | Cache by query string settings. |
| cacheByQueryString.option | 'ignore' \| 'varies' \| 'whitelist' \| 'blacklist' | Cache by query string option. |
| cacheByQueryString.list? | string[] | List of query string parameters to use for caching. |


```js
// azion.config.cjs
module.exports = {
build: { preset: "opennextjs", polyfills: true },
origin: [{ name: "origin-storage-default", type: "object_storage" }],
functions: [{ name: "handler", path: ".edge/worker.js" }],
cache: [
{
name: 'Default Cache',
browser: { maxAgeSeconds: 3600 },
edge: { maxAgeSeconds: 7200 },
},
],
rules: {
request: [
{
name: "Set storage origin for _next/static",
match: "^/_next/static/",
behavior: { setOrigin: { name: "origin-storage-default", type: "object_storage" }, deliver: true },
},
{
name: "Deliver Static Assets",
match: ".(css|js|ttf|woff|woff2|pdf|svg|jpg|jpeg|gif|bmp|png|ico|mp4|json)$",
behavior: { setOrigin: { name: "origin-storage-default", type: "object_storage" }, deliver: true },
},
{
name: "Execute Function",
match: "^/",
behavior: { runFunction: "handler", forwardCookies: true },
},
],
},
};
```

---

### Local Development

Use the [Azion CLI](/en/documentation/products/cli/) for local development:

```sh
azion dev
```

This runs your Application locally, simulating the Azion platform. [See Troubleshooting](/en/documentation/products/guides/opennext/troubleshooting/) for tips on debugging and log monitoring.

---

### Deployment

Deploy your app to Azion Web Platform:

```sh
azion deploy
```

Or use the Azion CLI to deploy to Azion Web Platform using local deployment:

```sh
azion deploy --local
```

---

### Best Practices & Troubleshooting

- See [Known Issues](/en/documentation/devtools/azion-edge-runtime/compatibility/nextjs/#known-issues) for important config notes.
- See [Troubleshooting](/en/documentation/products/guides/opennext/troubleshooting/) for local dev, logging, and debugging tips.
- Explore [Examples](/en/documentation/devtools/azion-edge-runtime/compatibility/nextjs/#examples) for starter projects and templates.
- For advanced caching, see [Caching](/azion/caching).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

link ta correto?

Loading