I was able to deploy a web app created with Next.js on Firebase, but when I try to interact with it, I encounter the following error, and the program exits prematurely:
Memory limit of 256 MiB exceeded with 260 MiB used. Consider increasing the memory limit, see https://cloud.google.com/functions/docs/configuring/memory
Even though I increased the memory allocation to 512MiB from the Google Cloud Console and redeployed Cloud Functions, the console shows that it's changed to 512MiB, but I still get the same error when interacting with the app, indicating that the changes haven't taken effect. When I attempt to reflect the changes by redeploying from my local environment using firebase deploy
, the memory allocation reverts to the initial value of 256MiB. How can I deploy with a memory allocation of 512MiB?
I ran into this same issue and was able to resolve it by specifying the amount of memory to allocate for the Next.js SSR function by editing the frameworksBackend
section of the firebase.json
file in the root of my project.
{
"functions": [
{
"runtime": "nodejs18",
"source": "functions",
"codebase": "default",
"ignore": [
"node_modules",
".git",
"firebase-debug.log",
"firebase-debug.*.log"
],
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint",
"npm --prefix \"$RESOURCE_DIR\" run build"
]
}
],
"hosting": {
"source": ".",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"frameworksBackend": {
"region": "us-central1",
"memory": "512MiB"
}
}
}
The options able to be used in the frameworksBackend
section are the same as for any 2nd gen Cloud Function. The complete list is available at firebase-functions/v2/https.httpsOptions.
More documentation can be viewed at Firebase CLI & Web Frameworks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With