Migrating Firebase Cloud Functions to Node 8

The purpose of this post is not to give a comprehensive guide but to point out a few potential issues while migrating from Node 6 to Node 8. The requirements are straightforward as stated in the official documentation.

  • Make sure firebase-functions library is 2.0.0+
    npm install firebase-functions@latest --save
  • Make sure firebase-tools is version 4.0.0+
    npm install -g firebase-tools --upgrade
  • Add "engines": {"node": "8"} to the package.json in functions/ directory.

Now my experience with a few remarks. This worked fine when I made my changes and deployed from my local computer. However, I had some issues with the Cloud Build configuration that we use for our CI/CD. In our case, the issue surfaced itself as syntax errors for async/await usage. I thought either we were using the wrong node version or the wrong firebase-tools version.

In essence it was related to how we built the firebase-tools image for the Cloud Build configuration. Our Dockerfile initially looked like this:

# Node 6
FROM node:boron

# install Firebase CLI
RUN npm install -g firebase-tools
ENTRYPOINT ["/usr/local/bin/firebase"]

This caused the firebase CLI to use node6 while running firebase deploy as a Cloud Build step. It was a bit hard to see the problem right away because building this image was a rare step in the deployment process. We just used it to build the CLI and put it onto Google Container Registry and pretty much forgot about it. The ideal way would have been tagging different node versions of firebase CLI, but it didn’t occur to me at the time.

Long story short, when you migrate your Firebase Cloud Functions to Node 8 and you are a Cloud Build user, don’t forget to rebuild the firebase-tools image with the right node version as well. The correct one looks like:

# Node 8
FROM node:carbon

# install Firebase CLI
RUN npm install -g firebase-tools
ENTRYPOINT ["/usr/local/bin/firebase"]

Hope it saves you some time if you end up on this part of the internet.

Cheers,