Need help with firebase-functions-next-example?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

221 Stars 25 Forks Other 53 Commits 0 Opened issues


Host a Next.js SSR React app on Cloud Functions for Firebase with Firebase Hosting

Services available


Need anything else?

Contributors list

# 8,790
2 commits
# 308,988
1 commit
# 548,816
1 commit

🚨 deprecated, new example at firebase-gcp-examples

Next.js SSR app on Cloud Functions for Firebase with Firebase Hosting

Host a Next.js SSR React app on Cloud Functions for Firebase with Firebase Hosting.

Here is the accompanying Medium PostA new post is being written to describe the new project structure, Firebase partial deployments, Firebase support of pre/post-deploy hooks and what problems these new features solve.

styled with Prettier


Host your SSR Next.js app on Cloud Functions enabling a low-cost, auto-scaling SSR app experience leveraging Firebase's sweet developer experience.


Firebase Hosting can rewrite routes to a Cloud Function that serves our Server-side Rendered Next.js app. Using a rewrite rule that catches ALL routes we can then host our SSR app on our Firebase Hosting URL instead of the Firebase Cloud Function URL.

instead of:

we can use:

Next.js can then be used to achieve SSR React with Hot-Module Reloading, server and client-side routing, route level code-splitting, route prefetching and more!

A number of issues with Hosting SSR on Firebase were overcome with this method. Please refer to the Medium Post before creating issues here.


  • This example uses

    as a devDependency which is run from the
    folder via
    . Yarn will run scripts from either the
    or binary scripts from
    npm run
    does not check the
    folder for executables, so if you use
    you will either have to change the scripts to explicitly run the
    binary from
    or install
    globally and remove it from the devDeps list. Have a look at the Next.js repo's example for how I recommend using
  • Ensure you're running Node

    as the functions emulator requires this. I recommend asdf as a version manager and have add an asdf
    file to define the Node runtime.
  • If using

    you may receive the following error on your deployed Cloud Function:
    { Error: Cannot find module '@babel/runtime/regenerator'...

    Despite next.js having

    as a dependency, you must install it as a dependency directly in this project.


git clone
cd firebase-functions-next-example
yarn install

Login to Firebase CLI

This is used as a dev-dependency instead of a global install. I've found this to be a much nicer dev experience.

yarn fblogin

Next.js Development

Standard Next.js development with Hot-module Reloading etc

yarn dev

Local Testing

yarn serve

This finally works now! Note: you must have a valid Firebase project id defined in the

file as the
command does check that the project exists. I believe this is to do with ensuring the relative routes align with your deployed application as the
 is used in your URLs.

For those who want to dig deeper into what's actually happening here run this command:

yarn serve --debug

Deploy to Firebase

You will need to connect the project to your Firebase project. Edit the name in .firebaserc or run

firebase init
and choose not to override any files.

Deploy Hosting resources and the rewrite Cloud Function

yarn deploy-app

Deploy functions not used for the SSR

Deploy all functions specified in the function group. Edit this script to add more function groups. - see Partial deploys docs for how to use function groups.

yarn deploy-funcs

Deploy everything to Firebase

yarn deploy-all


yarn clean

A note on Code Compatibility

Everything was tested on Ubuntu 17.04 with Bash. This should work on Bash on Ubuntu on Windows without any changes. If you wish for Windows native support please submit an issue so we can work on Windows compatibility. Please report any macOS errors as I do not have access to a device to test. My development environment can be found here.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.