Failed: build exceeded memory limit and was terminated

I have a large project and migrating Cloudflare, Trying to deploy to Cloudflare pages but while building the application I get this error.

Failed: build exceeded memory limit and was terminated

Also I get this message when I build the application locally with npx @cloudflare/next-on-pages@latest.
FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory

is there any way that I can increase the memory in while building in pages? or any other suggestions?

thanks

When you run into this locally, something is very wrong with your code.
You can generally limit the ammount of RAM node can use with:

NODE_OPTIONS="--max-old-space-size=8192" (sets it to 8GB)

But everything bevore Node v10 is very inefficient, when it comes to ressource management. So if you use an old Node version, please consider upgrading to a modern Node version.