The new way (next-on-pages) builds to a Next.JS server that runs on Pages Functions, so that you can

The new way (next-on-pages) builds to a Next.JS server that runs on Pages Functions, so that you can use everything normally from Next.JS and get server-side rendering, Next.JS redirects, etc.
10 Replies
Isaac McFadyen
Isaac McFadyenOP•2y ago
Pages Functions are similar to Workers, if you've used them, meaning they're only "on" when a request is coming in. So you're not always paying for hosting either.
GetPsyched
GetPsyched•2y ago
so I first host my project on pages, then head to pages functions? yeah, I've read a little bit about them what I didn't understand is how is a pages function deployed since my nextjs project will be on pages first, right?
Isaac McFadyen
Isaac McFadyenOP•2y ago
You have two options: 1. Use static Next.JS on Pages, which is free for unlimited requests and traffic, but requires your site to export statically and doesn't allow using Next.JS redirects. You upload normally and specify your build command as npm run export (I think?) 2. Use next-on-pages, which is what that template you saw before is using. It will automatically build and deploy your site to a Function, no setup required aside from uploading to Pages. It also allows you to use Next.JS server-side rendering and redirects. If you want to go with method 2, just upload your site as normal and use the Next.JS template that you saw.
GetPsyched
GetPsyched•2y ago
Interesting. so my Next.JS rewrites will work as normal?
Isaac McFadyen
Isaac McFadyenOP•2y ago
If you use next-on-pages they should, yes.
GetPsyched
GetPsyched•2y ago
I see. What about the default build directory in the template? I leave it as is?
Isaac McFadyen
Isaac McFadyenOP•2y ago
Yup, that template should be accurate.
GetPsyched
GetPsyched•2y ago
Cool. I'll try this out in a bit
Isaac McFadyen
Isaac McFadyenOP•2y ago
Sounds good - feel free to post here if you run into troubles 🙂
GetPsyched
GetPsyched•2y ago
Sure! Thanks for the help till now Seems like I missed something
Error: Could not access built-in Node.js modules. Please make sure that your Cloudflare Pages project has the 'nodejs_compat' compatibility flag set.
Error: Could not access built-in Node.js modules. Please make sure that your Cloudflare Pages project has the 'nodejs_compat' compatibility flag set.
Fixed it

Did you find this page helpful?