Gotcha: Google Cloud Functions with a Build Step

December 01, 2018

Ok, I’m going to admit that I’m not a huge fan of dev-ops. Anything I can automate away I’ll automate. Anything I can delegate to an inexpensive service to maintain and scale I will. So, as a JavaScript developer, it’s probably no surprise that I’m a fan of Google Cloud Functions.

Cloud functions allow me to focus on getting the logic written and leaving the uptime to the pros.

There was just one little problem. Every time I created a new repo that included a build step – in my case building from typescript – my deployments to gcloud would fail. I could run them in the gcloud simulator. However, on deployment I would be greeted with the following, lovely, error message:

(gcloud.beta.functions.deploy) OperationError: code=3, message=Function load error: File lib/functions/index.js that is expected to define function doesn’t exist

After beating my head against this issue enough times, I’ve finally decided to move the solution from my faulty memory to the internet at large.

Here’s the one-line fix. Add the following to your .gcloudignore file at the root of the repo:

#!include: .gitignore

Understandably we add the build directory for the repo to the .gitignore file. It turns out that gcloud functions respects the .gitignore when building your project and doesn’t see the /dist, /build, or /lib directory that has the code expected to run for your function.

It’s such a small thing, but I hope this saves you from beating your head on your desk in the future just as I hope it saves me.


Profile picture

👋 Hi, I'm Bob. I'm a User Experience designer turned Front-end Software Engineer working @FwdNetworks in Atlanta, GA. I love building effective and delightful user interfaces for organizations making a positive difference in the world.

You can also find me on GitHub, LinkedIn, Micro.blog, or Twitter

© 2021, Bob Owen