"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > 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?

Published on 2024-11-17
Browse:788

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).

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3