cloudflare / next-on-pages

CLI to build and develop Next.js apps for Cloudflare Pages
https://www.npmjs.com/package/@cloudflare/next-on-pages
MIT License
1.28k stars 125 forks source link

[⚡ Feature]: Supporting Next.js runtime Node.js #647

Open lcswillems opened 9 months ago

lcswillems commented 9 months ago

Description

I see Cloudflare supporting more and more Node.js modules.

Additional Information

No response

Would you like to help?

dario-piotrowicz commented 8 months ago

Hi @lcswillems 👋

Thanks for the issue 🙂, unfortunately I think that supporting the Node.js runtime is quite out of the question, mainly for two reasons:

The only practical solution I can think that would address both issues above would be to, actually make @cloudflare/next-on-pages work with both runtimes, and for node runtimes have the lambda(s) deployed to AWS, although that would introduce many issues:

Additionally (likely a personal opinion)... this project is called next-on-pages as it aims to allow running a Next.js applications on the Cloudflare Pages platform, so having it more generic and include AWS (or whatever else platform) seems out of scope to me and not something that this project was designed to do/created for.

Please let me know what you think of the above 🙂

If you have any potential solutions/ideas please also feel free to throw them my way 😄

lcswillems commented 8 months ago

Hi @dario-piotrowicz , what about just transforming the AWS lambda into workers? Doesn't seem too hard? And it would fail only if I use node modules not supported by Cloudflare.

dario-piotrowicz commented 8 months ago

@lcswillems as I mentioned above:

This adapter works by generating a worker using the Vercel CLI build command
(vercel build) output, such output comprises of edge functions and (AWS) lambda
functions, the adapter collects the code from the former to build the worker and
discards the latter (when discarding the code doesn't generate a loss of functionality,
if it does then the adapter's build process fails). The latter is code very AWS lambda
specific and not something we can really use (unless we were to deploy it to AWS).

The Vercel build generates complex lambdas which usually contain multiple routes bundled and grouped in an optimized way so that they grow as big as they can without reaching the AWS lambdas max side (50MB). So besides other things here, opposite to what we have with edge functions, there isn't even a 1-to-1 relationship between lambdas and routes.

It is as I said an AWS specific build, so pretty useless for us. I did look into it in depth a while back (looked wether we could infer any useful information/extract any useful code from the lambdas output I mean) which gives me confidence in saying that there, in my opinion, isn't really anything valuable from the lambdas that we could reuse 😕