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

module: using replace caused the compiler to search for non-exist go.mod #41793

Closed
xrfang opened this issue Oct 5, 2020 · 4 comments
Closed

module: using replace caused the compiler to search for non-exist go.mod #41793

xrfang opened this issue Oct 5, 2020 · 4 comments

Comments

@xrfang
Copy link

@xrfang xrfang commented Oct 5, 2020

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

$ go version

go version go1.15 linux/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/xrfang/.cache/go-build"
GOENV="/home/xrfang/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/xrfang/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/xrfang/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build933985160=/tmp/go-build -gno-record-gcc-switches"

What did you do?

In order to debug problems in my package https://github.com/xrfang/hxdump, I used replace in the go.mod file of a project:

`module bscli

go 1.14

replace github.com/xrfang/hxdump => /home/xrfang/git/hxdump

require (
github.com/augustoroman/hexdump v0.0.0-20190827031536-6506f4163e93
github.com/mdp/qrterminal v1.0.1
github.com/xrfang/go-res v1.3.0
github.com/xrfang/hxdump v0.0.0-20201005071519-c037229348d4
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c
)
`

What did you expect to see?

The project should be compiled without problem.

What did you see instead?

go: github.com/xrfang/hxdump@v0.0.0-20201005071519-c037229348d4: parsing ../../hxdump/go.mod: open /home/xrfang/git/hxdump/go.mod: no such file or directory

The module is cached under: /home/xrfang/go/pkg/mod/github.com/xrfang/hxdump@v0.0.0-20201005071519-c037229348d4 , there is no go.mod in that directory.

@xrfang
Copy link
Author

@xrfang xrfang commented Oct 5, 2020

I have done go clean -modcache -cache -testcache, no effect whatsoever.

@bcmills
Copy link
Member

@bcmills bcmills commented Oct 5, 2020

A filesystem-local replace directive requires a go.mod file at the root of the replacement directory, even if one is not normally present for that module. That is to prevent accidentally writing a replace for individual packages within a module, which is not a supported operation.

To make this replacement work, you can do: (cd /home/xrfang/git/hxdump && go mod init github.com/xrfang/hxdump).

CC @jayconrod @matloob

@bcmills
Copy link
Member

@bcmills bcmills commented Oct 5, 2020

Duplicate of #30847

@bcmills bcmills marked this as a duplicate of #30847 Oct 5, 2020
@bcmills bcmills closed this Oct 5, 2020
@xrfang
Copy link
Author

@xrfang xrfang commented Oct 6, 2020

@bcmills I suggest that the team consider improve the error prompt. Instead of:

go: github.com/xrfang/hxdump@v0.0.0-20201005071519-c037229348d4: parsing ../../hxdump/go.mod: open /home/xrfang/git/hxdump/go.mod: no such file or directory

How about:

go: github.com/xrfang/hxdump@v0.0.0-20201005071519-c037229348d4: missing required go.mod under /home/xrfang/git/hxdump

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.