简体   繁体   中英

Go: Cannot find package in any of Vendor Tree, $GOROOT or $GOPATH even though a private package exists in Vendor Tree

Here's my project structure:

在此处输入图像描述

Here's my mod file:

module github.com/bloodcompany/blood-microservices/stores/sync-stores-google-sheet-to-firestore

go 1.16

require (
    cloud.google.com/go/firestore v1.6.1 // indirect
    cloud.google.com/go/kms v1.4.0 // indirect
    github.com/bloodcompany/blood-microservices/utils v1.0.0
)

replace (
    github.com/bloodcompany/blood-microservices/models => ../../models
    github.com/bloodcompany/blood-microservices/utils => ../../utils
)

Here is my import in "function.go" file:

import (
    "github.com/bloodcompany/blood-microservices/utils"
)

The problem: When I deploy my function to server, I get below error in the Terminal. You can see in my project structure that the package that seems missing in the error is already available under Vendor Tree. But the error still appears. What could have possibly gone wrong?

ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Build failed: src/stores/function.go:9:2: cannot find package "github.com/bloodcompany/blood-microservices/utils" in any of:
        /workspace/src/stores/vendor/github.com/bloodcompany/blood-microservices/utils (vendor tree)
        /layers/google.go.runtime/go/src/github.com/bloodcompany/blood-microservices/utils (from $GOROOT)
        /workspace/src/github.com/bloodcompany/blood-microservices/utils (from $GOPATH); Error ID: 2f5e35a0

Note: My project is not in the location of $GOPATH. Is this an issue? $GOPATH location is "C:\Users\thisa\go" while the project is on another location.

There are two possible issues here:

Lack of go.mod

According to the documentation , your destination needs to have a go.mod file.

If the path on the right side of the arrow is an absolute or relative path (beginning with./ or../), it is interpreted as the local file path to the replacement module root directory, which must contain a go.mod file. The replacement version must be omitted in this case.

The files are not there

It looks like you're referencing files outside of your project root. Are those files being downloaded to wherever they are being deployed to? If they are downloaded, the problem is probably the one above.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM