Switching NextJS from Vercel to Cloudflare

November 8, 20254 min read

If you're reading this then that means this migration was a success 🎉.

I've been a massive fan of both Cloudflare and Vercel for years now, scaling NextJS apps from 0 to millions of users on both platforms. This is a migration that has been "in the oven" for some time, and I'm excited to finally be able to share my experience with you!

Why migrate?

Running very large applications on Vercel gets expensive, and the all too frequent changes to their billing structure and plans has left myself and a lot of my colleagues feeling like we're in a sinking ship.

If you are price sensitive, or are running a large dynamic application, then you may find yourself feeling the same way. Fortunately though, the captain does not have to go down with the ship.

Here's a quick summary of some of the pros for moving to Cloudflare:

  • Incredibly generous free tier
  • Deep integration with other Cloudflare products
  • If you're already proxying with Cloudflare to cache assets, you can save a double proxy

However, it's also important to understand the tradeoffs:

  • OpenNext does not support all NextJS features
  • Switching your application may not be possible due to runtime differences
  • The Cloudflare DX is simply nowhere close to Vercels
  • The Cloudflare platform has been under very heavy development and some features may not be fully polished, documented, or even work well

Why am I migrating?

Put simply, while I love Vercels DX I find myself leaning more and more towards fullstack Cloudflare, and because of this it makes sense to move the applications that I run over to them.

One of the biggest reasons I'm moving towards Cloudflare is how AI-friendly their platform is. Using Claude Code, you can point to Cloudflares MCP servers and have Claude build and deploy applications for you. The experience feels magical, and it's an experience that I just can't get with Vercel.

Make no mistake, I'm going to miss Vercel, and I have at least 1 project that has reached a scale that is unlikely to work on OpenNext, but as time goes on I expect this workflow to accelerate and having cheap access to hosting fullstack apps is what's important to me.

How did I migrate?

The best way to move a NextJS application to Cloudflare is with OpenNext. They provide an adapter that takes the build from next build and transforms it into a Cloudflare Worker compatible bundle.

To give you an idea of how simple this process actually is, below is a screenshot showing the total number of files I needed up update to get this deployed correctly.

Note that the edge runtime is not supported, so if you're using it expect a lot more updates!

Gotchas

Okay, this is the part that I wish someone else had already written for me.

incrementalCache

When setting up OpenNext, pay special attention to the documentation on open-next.config.ts. In particular, make sure you add incrementalCache. Without this, statically rendered pages won't be cached and the Cloudflare Worker will fall back to dynamic server rendering.

In my case this was leading to cryptic errors in the Cloudflare logs and 500 errors thrown.

If you're having trouble with types, don't forget to add open-next.config.ts to your tsconfig.json exlcude array!

Node Compat with fs

In my case, the wrangler config had the wrong compatibility date which caused fs commands to throw.

The date I used is 2025-09-15, which ensures that you have the V2 compatibility with NodeJS in your worker.

Observing errors

I'd recommend that you also add the following JSON to your wrangler config. This will allow you to capture errors and debug any problems.

"observability": {
    "logs": {
        "enabled": true,
        "head_sampling_rate": 1,
        "invocation_logs": true,
        "persist": true
    }
}

Wrapping up

Assuming you've followed the OpenNext docs and have also successfully deployed your application, congrats!

If not... what are you waiting for?

Thanks so much for reading, see you next time!