Home  >  Article  >  Backend Development  >  How to Resolve \"Build failed: go: parsing /models/go.mod: open /models/go.mod: no such file or directory\" Error When Deploying Go Cloud Functions with Go Modules?

How to Resolve \"Build failed: go: parsing /models/go.mod: open /models/go.mod: no such file or directory\" Error When Deploying Go Cloud Functions with Go Modules?

Susan Sarandon
Susan SarandonOriginal
2024-10-29 00:31:02794browse

How to Resolve

Deploying Google Cloud Function with Go Modules Error

When attempting to deploy a Google Cloud Function in Go 1.11 using Go modules, developers may encounter the error, "Build failed: go: parsing /models/go.mod: open /models/go.mod: no such file or directory."

Go Module Structure

Go modules prefer modules over vendors, which can lead to the error if a go.mod file is present with a replace directive pointing one level up. The function upload only includes the directory with the function at the root, not the directories one level up.

Solution

To resolve this issue, avoid uploading the go.mod/go.sum files and use vendor instead. With gcloud, create a .gcloudignore file to ignore these files during upload. For more details, refer to the Google Cloud documentation (link provided in the answer).

The above is the detailed content of How to Resolve \"Build failed: go: parsing /models/go.mod: open /models/go.mod: no such file or directory\" Error When Deploying Go Cloud Functions with Go Modules?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn