Deploying Nextjs app on Cloudflare workers

We must have wrangler installed globally:

npm install -g wrangler

In the project directory:

npm install --save-dev @opennextjs/cloudflare

In the project dir create wrangler.toml file

and add next content to it:

name = "my-next-cloudflare-app"

compatibility_date = "2024-12-14" // date of app creation or update
compatibility_flags = [ "nodejs_compat" ]

main = ".worker-next/index.mjs"
assets = { directory = ".worker-next/assets", binding = "ASSETS" }

add to package.json:

    "build:worker": "cloudflare",
    "dev:worker": "wrangler dev --port 8771",
    "preview:worker": "npm run build:worker && npm run dev:worker",
    "deploy:worker": "npm run build:worker && wrangler deploy",
 
start preview by:
npm run preview:worker
and deploy:
npm run deploy:worker
 

to watch Seriously? Did you know you can deploy a NextJS App on Cloudflare Workers?

to read Cloudflare Docs Workers> Frameworks> Framework guides> Next.js