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

cmd/go: get fails to get a package when mod file has replace in a repo that imports packages from another go module in the same repository #35693

Closed
dayadev opened this issue Nov 19, 2019 · 9 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@dayadev
Copy link

dayadev commented Nov 19, 2019

What version of Go are you using (go version)?

go version go1.13.4 darwin/amd64

Does this issue reproduce with the latest release?

yes it does

What operating system and processor architecture are you using (go env)?

go env Output
GO111MODULE=""
GOARCH="amd64"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.13.4/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.13.4/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/_4/g37z5y0j0t7dppmsyxymdsx00000gn/T/go-build977671086=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?


api
├── apiA
│   ├── apiA.go
│   └── go.mod
└── lib
    ├── go.mod
    └── lib.go

Here is my mod file contents

apiA mod contents


module api/apiA

replace api/lib => ../lib

require (
    github.com/fatih/structs v1.1.0 // indirect
    github.com/grpc-ecosystem/go-grpc-middleware v1.1.0 // indirect
    github.com/sirupsen/logrus v1.4.2
    api/lib v0.0.0-00010101000000-000000000000 // indirect
)

In the above mod file last line the the require api v0.0.0-00010101000000-000000000000 is actually generated for the module in lib directory

Everything works fine as the code builds and runs fine but when I try to get a package from github with

go get github.com/spf13/viper@v1.5.0

What did you expect to see?

expected to get the package and add it to go.mod file

What did you see instead?

It throws below error

go: malformed module path "api/lib": missing dot in first path element

api/lib is referring to my module in lib directory and not sure why its making an http call to get api/lib though I used replace

@seankhliao
Copy link
Member

shouldn't the replacement path be ../lib?

@dayadev
Copy link
Author

dayadev commented Nov 19, 2019

shouldn't the replacement path be ../lib?

Sure. Even if its so, that is not solving the issue that I am having

@seankhliao
Copy link
Member

based on the information you gave, your current setup (ignoring the go get) won't build because your replace points to some nonexistent directory

if you fix the replace it will build and will go get properly (reason being it needs the entire dependency tree for version selection)

@dayadev
Copy link
Author

dayadev commented Nov 19, 2019

based on the information you gave, your current setup (ignoring the go get) won't build because your replace points to some nonexistent directory

if you fix the replace it will build and will go get properly (reason being it needs the entire dependency tree for version selection)

May I know why api/lib is non existent directory ?

@seankhliao
Copy link
Member

your replace is ../api/lib so go up from api/libA into api, go down into api/api, then down again into api/api/lib which doesn't exist in the directory structure you showed

@tmthrgd
Copy link
Contributor

tmthrgd commented Nov 19, 2019

This seems like a duplicate of #35273.

@dayadev
Copy link
Author

dayadev commented Nov 19, 2019

your replace is ../api/lib so go up from api/libA into api, go down into api/api, then down again into api/api/lib which doesn't exist in the directory structure you showed

Ah. I had to create an example as I cannot give away the structure I am actually using. but my local structure builds fine and go get fails at the last line of require section of go.mod
Updated now.

@toothrot toothrot changed the title Go get fails to get a package when mod file has replace in a repo that imports packages from another go module in the same repository cmd/go: get fails to get a package when mod file has replace in a repo that imports packages from another go module in the same repository Nov 22, 2019
@toothrot toothrot added this to the Backlog milestone Nov 22, 2019
@toothrot
Copy link
Contributor

Hi @dayadev,

This sounds similar to #35273. What does the require statement in api/apiA.go? What does the package declaration at the top of lib/lib.go look like?

@toothrot toothrot added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Nov 22, 2019
@gopherbot
Copy link

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

@golang golang locked and limited conversation to collaborators Dec 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

5 participants