|
| 1 | +--- |
| 2 | +title: Get Started With OpenNext |
| 3 | +description: >- |
| 4 | + 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. |
| 5 | +permalink: /documentation/products/guides/opennext/get-started/ |
| 6 | +meta_tags: >- |
| 7 | + Next.js compatibility, Azion Web Platform, SSR, SSG, Middleware Features, |
| 8 | + Static Generation, Server-side Rendering, Next.js Routing, Next.js |
| 9 | + Performance, Next.js Integrations |
| 10 | +namespace: documentation_guides_opennext_get_started |
| 11 | +--- |
| 12 | + |
| 13 | + |
| 14 | +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. |
| 15 | + |
| 16 | +--- |
| 17 | + |
| 18 | +### Prerequisites |
| 19 | + |
| 20 | +- [CLI Installed](/en/documentation/products/azion-cli/overview/#installing-azion-cli). |
| 21 | + |
| 22 | +--- |
| 23 | + |
| 24 | +#### Creating a New Next.js App |
| 25 | + |
| 26 | +To create a new Next.js app pre-configured for Azion: |
| 27 | + |
| 28 | +```sh |
| 29 | +npx create-next-app@14.2.4 my-next-app --use-npm |
| 30 | +cd my-next-app |
| 31 | +npm install @aziontech/opennextjs-azion@latest |
| 32 | +``` |
| 33 | + |
| 34 | +Or use a starter template: |
| 35 | + |
| 36 | +- [Next.js + TypeScript + Tailwind Template](https://github.com/aziontech/azion-samples/tree/dev/templates/opennextjs/nextal-next-typescript-tailwind) |
| 37 | +- [Node Playground (Next.js 13)](https://github.com/aziontech/bundler-examples/tree/main/examples/nextjs/node-playground-13) |
| 38 | + |
| 39 | +--- |
| 40 | + |
| 41 | +#### Existing Next.js Apps |
| 42 | + |
| 43 | +1. Install the Azion Adapter: |
| 44 | + |
| 45 | +```sh |
| 46 | +npm install @aziontech/opennextjs-azion@latest |
| 47 | +``` |
| 48 | + |
| 49 | +2. Configure `open-next.config.ts`: |
| 50 | + |
| 51 | +Create or update `open-next.config.ts` in your project root. Example: |
| 52 | + |
| 53 | +```ts |
| 54 | +import { defineAzionConfig } from "@aziontech/opennextjs-azion"; |
| 55 | + |
| 56 | +export default defineAzionConfig({ |
| 57 | + // See /azion/caching for advanced options |
| 58 | +}); |
| 59 | +``` |
| 60 | + |
| 61 | +3. Update `tsconfig.json`: |
| 62 | + |
| 63 | +:::warning |
| 64 | +Your `tsconfig.json` must include: ```json "moduleResolution": "bundler" ``` This is required for correct build and runtime behavior. |
| 65 | +::: |
| 66 | + |
| 67 | +If you encounter issues with ESM or `open-next.config.ts`, you may need to add: |
| 68 | + |
| 69 | +```json |
| 70 | +"exclude": ["node_modules", "open-next.config.ts"] |
| 71 | +``` |
| 72 | + |
| 73 | +See [Known Issues](/en/documentation/devtools/azion-edge-runtime/compatibility/nextjs/#known-issues) for more details. |
| 74 | + |
| 75 | +1. Azion CLI Build and Deploy: |
| 76 | + |
| 77 | +- `azion build`: Builds your app for Azion. |
| 78 | +- `azion preview`: Runs a local preview using Azion CLI. |
| 79 | +- `azion deploy`: Deploys to Azion Web Platform using Remote Deployment. |
| 80 | + - or `azion deploy --local` to deploy to Azion Web Platform using Local Deployment. |
| 81 | + |
| 82 | +5. Set Up Caching and Storage: |
| 83 | + |
| 84 | +See the [Caching Guide](/azion/caching) for how to configure Azion Object Storage and Cache for ISR/SSG. Example Azion config: |
| 85 | + |
| 86 | +```ts |
| 87 | +AzionCache |
| 88 | +Type definition for the cache configuration. |
| 89 | +``` |
| 90 | + |
| 91 | +Properties: |
| 92 | + |
| 93 | +| Property | Type | Description | |
| 94 | +| --- | --- | --- | |
| 95 | +| name | string | Name of the cache configuration. | |
| 96 | +| stale? | boolean | Whether to allow stale content. | |
| 97 | +| queryStringSort? | boolean | Whether to sort query string parameters. | |
| 98 | +| methods? | CacheMethods | HTTP methods to cache. | |
| 99 | +| post? | boolean | Whether to cache POST requests. | |
| 100 | +| options? | boolean | Whether to cache OPTIONS requests. | |
| 101 | +| browser? | BrowserCacheConfig | Browser cache settings. | |
| 102 | +| browser.maxAgeSeconds | number \| string | Maximum age for browser cache in seconds. | |
| 103 | +| edge? | EdgeCacheConfig | Cache settings. | |
| 104 | +| edge.maxAgeSeconds | number \| string | Maximum age for cache in seconds. | |
| 105 | +| cacheByCookie? | CacheByCookieConfig | Cache by cookie settings. | |
| 106 | +| cacheByCookie.option | 'ignore' \| 'varies' \| 'whitelist' \| 'blacklist' | Cache by cookie option. | |
| 107 | +| cacheByCookie.list? | string[] | List of cookies to use for caching. | |
| 108 | +| cacheByQueryString? | CacheByQueryStringConfig | Cache by query string settings. | |
| 109 | +| cacheByQueryString.option | 'ignore' \| 'varies' \| 'whitelist' \| 'blacklist' | Cache by query string option. | |
| 110 | +| cacheByQueryString.list? | string[] | List of query string parameters to use for caching. | |
| 111 | + |
| 112 | + |
| 113 | +```js |
| 114 | +// azion.config.cjs |
| 115 | +module.exports = { |
| 116 | + build: { preset: "opennextjs", polyfills: true }, |
| 117 | + origin: [{ name: "origin-storage-default", type: "object_storage" }], |
| 118 | + functions: [{ name: "handler", path: ".edge/worker.js" }], |
| 119 | + cache: [ |
| 120 | + { |
| 121 | + name: 'Default Cache', |
| 122 | + browser: { maxAgeSeconds: 3600 }, |
| 123 | + edge: { maxAgeSeconds: 7200 }, |
| 124 | + }, |
| 125 | + ], |
| 126 | + rules: { |
| 127 | + request: [ |
| 128 | + { |
| 129 | + name: "Set storage origin for _next/static", |
| 130 | + match: "^/_next/static/", |
| 131 | + behavior: { setOrigin: { name: "origin-storage-default", type: "object_storage" }, deliver: true }, |
| 132 | + }, |
| 133 | + { |
| 134 | + name: "Deliver Static Assets", |
| 135 | + match: ".(css|js|ttf|woff|woff2|pdf|svg|jpg|jpeg|gif|bmp|png|ico|mp4|json)$", |
| 136 | + behavior: { setOrigin: { name: "origin-storage-default", type: "object_storage" }, deliver: true }, |
| 137 | + }, |
| 138 | + { |
| 139 | + name: "Execute Function", |
| 140 | + match: "^/", |
| 141 | + behavior: { runFunction: "handler", forwardCookies: true }, |
| 142 | + }, |
| 143 | + ], |
| 144 | + }, |
| 145 | +}; |
| 146 | +``` |
| 147 | + |
| 148 | +--- |
| 149 | + |
| 150 | +### Local Development |
| 151 | + |
| 152 | +Use the [Azion CLI](/en/documentation/products/cli/) for local development: |
| 153 | + |
| 154 | +```sh |
| 155 | +azion dev |
| 156 | +``` |
| 157 | + |
| 158 | +This runs your Application locally, simulating the Azion platform. See [Troubleshooting](/en/documentation/products/guides/opennext/troubleshooting/) for tips on debugging and log monitoring. |
| 159 | + |
| 160 | +--- |
| 161 | + |
| 162 | +### Deployment |
| 163 | + |
| 164 | +Deploy your app to Azion Web Platform: |
| 165 | + |
| 166 | +```sh |
| 167 | +azion deploy |
| 168 | +``` |
| 169 | + |
| 170 | +Or use the Azion CLI to deploy to Azion Web Platform using Local Deployment: |
| 171 | + |
| 172 | +```sh |
| 173 | +azion deploy --local |
| 174 | +``` |
| 175 | + |
| 176 | +--- |
| 177 | + |
| 178 | +### Best Practices & Troubleshooting |
| 179 | + |
| 180 | +- See [Known Issues](/en/documentation/devtools/azion-edge-runtime/compatibility/nextjs/#known-issues) for important config notes. |
| 181 | +- See [Troubleshooting](/en/documentation/products/guides/opennext/troubleshooting/) for local dev, logging, and debugging tips. |
| 182 | +- Explore [Examples](/en/documentation/devtools/azion-edge-runtime/compatibility/nextjs/#examples) for starter projects and templates. |
| 183 | +- For advanced caching, see [Caching](/azion/caching). |
0 commit comments