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

Open
dayadev opened this issue Nov 19, 2019 · 8 comments

Comments

@dayadev
Copy link

@dayadev 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

This comment has been minimized.

Copy link

@seankhliao seankhliao commented Nov 19, 2019

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

@dayadev

This comment has been minimized.

Copy link
Author

@dayadev 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

This comment has been minimized.

Copy link

@seankhliao seankhliao 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)

@dayadev

This comment has been minimized.

Copy link
Author

@dayadev 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

This comment has been minimized.

Copy link

@seankhliao seankhliao 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

@tmthrgd

This comment has been minimized.

Copy link
Contributor

@tmthrgd tmthrgd commented Nov 19, 2019

This seems like a duplicate of #35273.

@dayadev

This comment has been minimized.

Copy link
Author

@dayadev 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

This comment has been minimized.

Copy link
Contributor

@toothrot toothrot commented Nov 22, 2019

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?

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