functions-framework-go: Cannot deploy to Google Cloud Functions
Deploying a Golang function to Google Cloud Functions errors with a reference this package, so this seems like the best place to report this.
The following command had been running for over a year without fail. This morning we tried it and it failed, and it has continued to fail since then as we attempt deploys in various scenarios to fix or work around the problem.
Deploy Command
gcloud functions deploy $FUNCTION_ID \
--quiet \
--project $MY_PROJECT \
--runtime go113 \
--entry-point=Server \
--trigger-http \
--timeout=540s \
--memory=4096MB
Google Cloud Deploy error
Our functions have just today (2021-09-25) spontaneously started failing to deploy. The error we get is:
ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Build failed: vendored dependencies must include “github.com/GoogleCloudPlatform/functions-framework-go”; if your function does not depend on the module, please add a blank import: _ “github.com/GoogleCloudPlatform/functions-framework-go”; Error ID: fd86168a
The build log is curiously empty:

import functions-framework-go
import (
_ "github.com/GoogleCloudPlatform/functions-framework-go"
)
yields a compile-time error:
package github.com/netpleadings/minutebox/services/json2word imports github.com/GoogleCloudPlatform/functions-framework-go: no Go files in /home/brian_minutebox_com/minutebox/services/docgen2/vendor/github.com/GoogleCloudPlatform/functions-framework-go
Import functions-framework-go/funcframework
import (
_ "github.com/GoogleCloudPlatform/functions-framework-go/funcframework"
)
yields a deploy error:
Deploying function (may take a while - up to 2 minutes)…⠛
For Cloud Build Logs, visit: https://console.cloud.google.com/cloud-build/builds;region=us-central1/3b5fb4af-132d-4cbf-b551-e299c04aa78a?project={ANON_PROJECTID} Deploying function (may take a while - up to 2 minutes)…failed.
ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Build failed: can’t load package: package functions.local/app: cannot find module providing package functions.local/app; Error ID: 1a663392
Change to go116
We changed the --runtime from go113 to go116. This had no impact and we still received the error.
Setup
❯ go version
go version go1.16.8 linux/amd64
❯ gcloud version
Google Cloud SDK 352.0.0
alpha 2021.08.06
beta 2021.08.06
bq 2.0.70
core 2021.08.06
gsutil 4.66
I initially tried this with Go 1.15 (that is prepackaged for Debian 11) and upgraded to see if that fixes it (but it did not).
We’re not sure where to go from here and any thoughts, advice, or input would be most welcome. We will cross-report to Google Cloud Support.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 3
- Comments: 17 (3 by maintainers)
Hey @shreejad, thanks for the link. I was able to resolve my issue (on go 1.13) by adding the
vendor/directory to the.gcloudignorefile, while leavinggo.modandgo.sumout of the.gcloudignore. This was a recommendation from Google Cloud Support.I believe the blank import we are suggesting in the Cloud Build logs is incorrect. It should be:
This aligns with the code that gets added by the functions-framework buildpack. @brianmhunt please give that a try and let us know if it fixes the issue. Sorry for the confusion.
Thanks for the report. We’re looking into it.
I had the same problem, solved it by changing
to
and adding this in my
init()func:I have no idea why this works.
The same problem appeared to me again with the version go v1.23.3. After rolling back to 1.22.2 it works normally. This is the message I have when deploy the GCF:
I have the dependency on other private project and thus use
go mod vendorI have the
import _ "github.com/GoogleCloudPlatform/functions-framework-go/funcframework"at my function go file.The problem appeared when I switched to go v1.23.3 and disappeared when I rolled back to v1.22.2
We can into a similar issue, and discovered that our issues was due to how
buildpackwas trying to compile our binary. We had to explicitly pass in the build arguments into thegcloud deploycommand.Previously, we were deploying with the following command on version
290.0.1ofgcloudwhich failed:We then upgraded to version
356.0.0ofgcloud, which allowed us to pass in the--set-build-env-varsflag:Thanks for the detailed error report @brianmhunt. Any more messages or details are welcome.
I’ve sent a message to members of the team.
I am investigating if this error may be caused by a Buildpack change for the Go Functions Framework, for example, https://github.com/GoogleCloudPlatform/buildpacks/commit/e3b1fbb25249e3b158500f787c45d75ebeb3e562