Search code examples
firebasenext.jsgoogle-cloud-functionsgoogle-cloud-runfirebase-tools

Quota limit when deploying Next.js to firebase with CLI


I am using the 'firebase deploy' command to deploy a Next.JS project to firebase.

When deploying functions, the command attempts to create a Cloud Run function to handle server side rendering.

I get this error.

!  functions: Your current project quotas don't allow for the current max instances setting of 100. Either reduce this function's maximum instances, or request a quota increase on the underlying Cloud Run service at https://cloud.google.com/run/quotas.
!  functions: You can adjust the max instances value in your function's runtime options:
        setGlobalOptions({maxInstances: 10})
Failed to update function projects/philantrho-threads/locations/europe-west1/functions/ssrphilantrhothreads

Functions deploy had errors with the following functions:
        firebase-frameworks-philantrho-threads:ssrphilantrhothreads(europe-west1)

I have attempted to setGlobalOptions in the server.js file like so

const { onRequest } = require('firebase-functions/v2/https');
const { setGlobalOptions } = require('firebase-functions/v2/options');

  setGlobalOptions({ maxInstances: 10});
  const server = import('firebase-frameworks');
  exports.ssrphilantrhothreads = onRequest({"region":"europe-west1"}, (req, res) => server.then(it => it.handle(req, res)));

But when I run 'firebase deploy', the file overwrites to the default code, removing setGlobalOptions :

const { onRequest } = require('firebase-functions/v2/https');
  const server = import('firebase-frameworks');
  exports.ssrphilantrhothreads = onRequest({"region":"europe-west1"}, (req, res) => server.then(it => it.handle(req, res)));

Solution


  • You will want to set max instances in your firebase.json like so:

    {
      "hosting": {
        "source": ".",
        "ignore": [
          "firebase.json",
          "**/.*",
          "**/node_modules/**"
        ],
     "frameworksBackend": {
          "maxInstances": 2
        }
      }
    }
    

    This should ensure that Cloud Run will read max instances and apply it.