skip to Main Content

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?

2

Answers


  1. Every time you deploy a function with the Firebase CLI, it will reset all of the function configurations. That’s how your memory setting keeps changing. If you want the same value every time you deploy, you should specify that value in the code of your function instead of modifying it in the console.

    There is documentation on how to change your function memory settings.

    Login or Signup to reply.
  2. If you change memory allocation on console you don’t need to redeploy functions because deployed code will already be running with new allocation you set.

    You can also set function memory allocation directly inside your code:

    import * as functions from 'firebase-functions'
    
    ....
    
    exports.myFunction = functions
      .runWith( {
        // '128MB', '256MB', '512MB', etc....
        memory: '1GB'
      } )
      .https.onRequest( () => { ... } )
    

    Now every time you deploy your function it will update memory allocation automatically so you doesn’t need to update it on console.

    You can also read more about this here.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search