nodejs_compat Compatibility Flag for Nextjs (Cloudflare Pages)

I can deploy my Nextjs website onto Vercel and Netlify directly from Github repo, one click no issues. But for some reason on Cloudflare Pages I get an error telling me I need to manually add "nodejs_compat" flag to production and build. Is there any reason for this? And is the Cloudflare team working on resolving this, or it will always be like this?
4 Replies
Chaika
Chaika2mo ago
Is there any reason for this? And is the Cloudflare team working on resolving this, or it will always be like this?
Cloudflare Pages uses Next-on-pages to run next.js, which requires some nodejs compatability functionality to work. Workers aren't node.js, but V8 Isolates (Chromium's JS Engine -- web like environment). next-on-pages requires some of those for some things like node:path and promises, and having it enabled also helps with any dependencies you have that might use it.
And is the Cloudflare team working on resolving this
It's more a feature then a bug, like "hey you're enabling some extra stuff outside of the normal scope of workers", although maybe could be better integration with next-on-pages to just do it for you or something.
, or it will always be like this?
Probably not exactly the same. Cloudflare has been working on converging Pages into Workers for a while now and recently added support for Static Assets and started recommending OpenNext over Next On Pages: https://opennext.js.org/cloudflare which has a slightly different (and maybe a bit easier, although still requiring nodejs_compat) setup
avidrunner
avidrunnerOP2mo ago
Oh OK thanks. If Cloudflare Workers aren’t NodeJS what are they using instead? Does this mean Vercel and Netlify use “nodejs workers”? I was under the impression AWS Lambda so whatever that uses In some sense is CloudFlare trying to avoid NodeJS on purpose for edge based functions? It makes me think of Deno and the steps it is trying to make for some reason but not sure if it’s related to this
Chaika
Chaika2mo ago
Oh OK thanks. If Cloudflare Workers aren’t NodeJS what are they using instead?
V8 Isolates: https://developers.cloudflare.com/workers/reference/how-workers-works/ V8 is the Javascript Engine Chrome uses, and Isolates are a cheap way to have virtual contexts essentially they're super super lightweight
Cloudflare Docs
How Workers works | Cloudflare Workers docs
The difference between the Workers runtime versus traditional browsers and Node.js.
Chaika
Chaika2mo ago
Not 100% sure what the other two are using. I think something like lambda/containers yea.
In some sense is CloudFlare trying to avoid NodeJS on purpose for edge based functions?
The more you virtualize, the more expensive cold starts/per customer instances are. You'd need a higher abstraction like containers/etc to separate each customer for security. Workers are silly fast, can get 0ms cold starts due to them using the TLS Handshake time to warm up the isolate, and silly cheap since they all share the same runtime. Worth noting though nodejs compat still isn't running them differently or with node.js, they're just enabling a bunch of node compatability features, essentially reimplementations of node functions. Still far from actual node.js, no file system or networking for example. But something you'd want people to have to opt into, to understand that it's only partial compatibility/not confuse it with an actual node env/not load what's not needed
Want results from more Discord servers?
Add your server