Skip to main content

OpenNext adapter

还没翻译译自英文(developers.cloudflare.com)本页 13 段都还没译

Recommended path

Cloudflare recommends vinext instead of OpenNext for new Next.js applications on Cloudflare Workers.

Use this guide to maintain an existing OpenNext application. Migrate to vinext when compatibility allows.

OpenNext adapts the output of next build so it can run on different platforms, including Cloudflare Workers.

Supported features

Most Next.js features are supported by the Cloudflare OpenNext adapter:

FeatureCloudflare OpenNext adapterNotes
App RouterSupported
Pages RouterSupported
Route HandlersSupported
React Server ComponentsSupported
Static Site Generation (SSG)Supported
Server-Side Rendering (SSR)Supported
Incremental Static Regeneration (ISR)Supported
Server ActionsSupported
Response streamingSupported
Asynchronous work with next/afterSupported
MiddlewareSupported
Image optimizationSupportedSupported through Cloudflare Images.
Partial Prerendering (PPR)SupportedPPR is experimental in Next.js.
Composable Caching ("use cache")SupportedComposable Caching is experimental in Next.js.
Node.js in MiddlewareNot yet supportedNode.js middleware introduced in Next.js 15.2 is not yet supported.

For detailed OpenNext documentation, refer to OpenNext for Cloudflare.

Configure OpenNext manually

Wrangler automatic configuration uses vinext for Next.js projects. To use OpenNext, configure the adapter manually.

  1. Install the OpenNext Cloudflare adapter.

    npmyarnpnpmbun

    npm i @opennextjs/cloudflare@latest
  2. Install Wrangler.

    npmyarnpnpmbun

    npm i -D wrangler@latest
  3. Add a Wrangler configuration file.

    In your project root, create a Wrangler configuration file with the following content:

    wrangler.jsoncwrangler.toml

    {
      "$schema": "./node_modules/wrangler/config-schema.json",
      "name": "my-app",
      "main": ".open-next/worker.js",
      "upload_source_maps": true,
      // Set this to today's date
      "compatibility_date": "2026-11-02",
      "compatibility_flags": [
        "nodejs_compat"
      ],
      "assets": {
        "directory": ".open-next/assets",
        "binding": "ASSETS"
      },
      "observability": {
        "enabled": true
      }
    }

    Note

    You must turn on the nodejs_compat compatibility flag and set your compatibility date to 2024-09-23 or later.

  4. Add an OpenNext configuration file.

    In your project root, create open-next.config.ts:

    import { defineCloudflareConfig } from "@opennextjs/cloudflare";
    
    export default defineCloudflareConfig();

    Use this file to configure OpenNext features such as caching. For more information, refer to OpenNext caching.

  5. Update package.json.

    Add scripts for previewing, deploying, and generating Cloudflare types:

    {
      "scripts": {
        "preview": "opennextjs-cloudflare build && opennextjs-cloudflare preview",
        "deploy": "opennextjs-cloudflare build && opennextjs-cloudflare deploy",
        "cf-typegen": "wrangler types --env-interface CloudflareEnv cloudflare-env.d.ts"
      }
    }

    Script usage

  6. Develop locally.

    Start the Next.js development server.

    npmyarnpnpm

    npm run dev
  7. Preview with OpenNext.

    Preview your application in the Workers runtime.

    npmyarnpnpm

    npm run preview
  8. Deploy your project.

    Deploy your project to Cloudflare Workers.

    npmyarnpnpm

    npm run deploy

Workers Builds

Workers Builds requires you to configure environment variables in Build variables and secrets.

This ensures the Next.js build has access to both public NEXT_PUBLIC_ variables and non-public variables required for static generation and server-side build work. For more information, refer to OpenNext environment variables.