Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when trying to deploy Google cloud function in Go 1.11 using go modules #743

sharkyze opened this issue Jan 29, 2019 · 2 comments


Copy link

@sharkyze sharkyze commented Jan 29, 2019

I originally posted this on stackoverflow:

I am having issues deploying a Google cloud function in Go 1.11 using Go modules. I have the following code structure in my GOPATH:
├── models
│   ├── go.mod
│   └── models.go
└── load
    ├── fn.go
    ├── go.mod
    ├── go.sum
    └── vendor
        │   └── ...
        │   ├── golang
        │   │   └── ...
        │   └── example
        │       └── models
        │           ├── go.mod
        │           └── models.go
        └── ...

the load/go.mod looks like the following:


require ( v0.0.0

replace => ../models

When I try to deploy the function using the command

gcloud functions deploy load-data --entry-point GCSNewFileTrigger --runtime go111 --trigger-resource new_data --trigger-event

I get the following error:

Deploying function (may take a while - up to 2 minutes)...failed.                                                                                                                                                                     
ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Build failed: go: parsing /models/go.mod: open /models/go.mod: no such file or directory
go: error loading module requirements

The commands go mod vendor and go mod verify run successfully locally and I can see my local package models in the vendor folder of load


This comment has been minimized.

Copy link

@tbpg tbpg commented Jan 29, 2019

Thank you for filing this issue!

Modules are preferred by the builder over vendor. If there is a go.mod, modules will be used. When you upload your function, it only includes the directory with your function at the root, not any directories one level up. So, when there is a go.mod and you have a replace directive pointing one level up, it will not work.

The solution is to vendor and not upload the go.mod/go.sum files. When using gcloud, you can create a .gcloudignore file to do this for you. See for more detail.

I'm going to close this issue as this repo is for hosting sample code, and is only watched by engineers working on those samples. Thank you for bringing this up!

@tbpg tbpg closed this Jan 29, 2019

This comment has been minimized.

Copy link

@sharkyze sharkyze commented Jan 30, 2019

Thank you so much for your answer. This fixed my problem 😀. Sorry for posting this here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.