(Imperative) `go get` fails for me with `cannot find module providing package`

All of a sudden, I can’t compile a Go project (I maintain) with go get and go build, I get all kinds of very persistent errors. When running go build:

cmd/pistol/main.go:10:2: no required module provides package github.com/adrg/xdg; to add it:
	go get github.com/adrg/xdg
cmd/pistol/main.go:9:2: no required module provides package github.com/alexflint/go-arg; to add it:
	go get github.com/alexflint/go-arg
cmd/pistol/main.go:8:2: no required module provides package github.com/doronbehar/magicmime; to add it:
	go get github.com/doronbehar/magicmime
previewer.go:15:2: no required module provides package al.essio.dev/pkg/shellescape; to add it:
	go get al.essio.dev/pkg/shellescape
internal_writers/archives.go:14:2: no required module provides package github.com/dustin/go-humanize; to add it:
	go get github.com/dustin/go-humanize
internal_writers/archives.go:12:2: no required module provides package github.com/jedib0t/go-pretty/v6/table; to add it:
	go get github.com/jedib0t/go-pretty/v6/table
internal_writers/archives.go:11:2: no required module provides package github.com/mholt/archives; to add it:
	go get github.com/mholt/archives
internal_writers/json.go:10:2: no required module provides package github.com/nwidger/jsoncolor; to add it:
	go get github.com/nwidger/jsoncolor
internal_writers/archives.go:13:2: no required module provides package github.com/sirupsen/logrus; to add it:
	go get github.com/sirupsen/logrus
internal_writers/archives.go:9:2: no required module provides package golang.org/x/term; to add it:
	go get golang.org/x/term

And if I run go mod tidy I get:

go: finding module for package al.essio.dev/pkg/shellescape
go: finding module for package github.com/mholt/archives
go: finding module for package github.com/adrg/xdg
go: finding module for package github.com/doronbehar/magicmime
go: finding module for package github.com/alexflint/go-arg
go: finding module for package github.com/sirupsen/logrus
go: finding module for package github.com/jedib0t/go-pretty/v6/table
go: finding module for package github.com/dustin/go-humanize
go: finding module for package github.com/nwidger/jsoncolor
go: finding module for package golang.org/x/term
go: finding module for package github.com/alecthomas/assert/v2
go: finding module for package github.com/alecthomas/repr
go: github.com/doronbehar/pistol imports
	al.essio.dev/pkg/shellescape: module al.essio.dev/pkg/shellescape@latest found (v1.6.0), but does not contain package al.essio.dev/pkg/shellescape
go: github.com/doronbehar/pistol imports
	github.com/doronbehar/magicmime: package github.com/doronbehar/magicmime provided by github.com/doronbehar/magicmime at latest version v0.1.0 but not at required version v0.1.1-0.20211127135329-3de4ff29dc49
go: github.com/doronbehar/pistol imports
	github.com/sirupsen/logrus: module github.com/sirupsen/logrus@latest found (v1.9.4), but does not contain package github.com/sirupsen/logrus
go: github.com/doronbehar/pistol/cmd/pistol imports
	github.com/adrg/xdg: module github.com/adrg/xdg@latest found (v0.5.3), but does not contain package github.com/adrg/xdg
go: github.com/doronbehar/pistol/cmd/pistol imports
	github.com/alexflint/go-arg: module github.com/alexflint/go-arg@latest found (v1.6.1), but does not contain package github.com/alexflint/go-arg
go: github.com/doronbehar/pistol/internal_writers imports
	github.com/dustin/go-humanize: module github.com/dustin/go-humanize@latest found (v1.0.1), but does not contain package github.com/dustin/go-humanize
go: github.com/doronbehar/pistol/internal_writers imports
	github.com/jedib0t/go-pretty/v6/table: module github.com/jedib0t/go-pretty/v6@latest found (v6.7.10), but does not contain package github.com/jedib0t/go-pretty/v6/table
go: github.com/doronbehar/pistol/internal_writers imports
	github.com/mholt/archives: module github.com/mholt/archives@latest found (v0.1.5), but does not contain package github.com/mholt/archives
go: github.com/doronbehar/pistol/internal_writers imports
	github.com/nwidger/jsoncolor: module github.com/nwidger/jsoncolor@latest found (v0.3.2), but does not contain package github.com/nwidger/jsoncolor
go: github.com/doronbehar/pistol/internal_writers imports
	golang.org/x/term: module golang.org/x/term@latest found (v0.43.0), but does not contain package golang.org/x/term
go: github.com/doronbehar/pistol/internal_writers imports
	github.com/alecthomas/chroma/v2 tested by
	github.com/alecthomas/chroma/v2.test imports
	github.com/alecthomas/assert/v2: module github.com/alecthomas/assert/v2@latest found (v2.11.0), but does not contain package github.com/alecthomas/assert/v2
go: github.com/doronbehar/pistol/internal_writers imports
	github.com/alecthomas/chroma/v2/lexers tested by
	github.com/alecthomas/chroma/v2/lexers.test imports
	github.com/alecthomas/repr: module github.com/alecthomas/repr@latest found (v0.5.2), but does not contain package github.com/alecthomas/repr

I tried e.g:

  • sudo rm -rf ~/.go && go mod tidy -v
  • env GOPROXY=direct go mod tidy -v

And all of these failed the same.

Luckily, since I use Nix with gomod2nix, I am able to build my project with nix build. However performing version bumps for go modules is impossible now…

Any idea why is that?

i think i hit this issue a good while back, it’s probably due to the path go is trying download the sources to is in store path

i want a consistent directory for all go projects so i set

GOPATH and GOMODCACHE to user xdg dirs

I already set GOPATH=$HOME/.go, and in the output of go env I see GOMODCACHE is automatically set to ~/.go/pkg/mod. Setting it explicitly to that value doesn’t help…

do you see anything strange comparing with the following?

$ go env
AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/ysun/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/ysun/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3665657411=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/home/ysun/Workspace/rfm/go.mod'
GOMODCACHE='/home/ysun/.cache/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/ysun/.local/share/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/nix/store/dimnagks1qsp7180yw74z0npp7z2ihs3-go-1.26.2/share/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/ysun/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/nix/store/dimnagks1qsp7180yw74z0npp7z2ihs3-go-1.26.2/share/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.26.2'
GOWORK=''
PKG_CONFIG='pkg-config'

No… Here’s the diff:

16c16
< GOCACHE='/home/doron/.cache/go-build'
---
> GOCACHE='/home/ysun/.cache/go-build'
19c19
< GOENV='/home/doron/.config/go/env'
---
> GOENV='/home/ysun/.config/go/env'
24c24
< GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3538663182=/tmp/go-build -gno-record-gcc-switches'
---
> GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3665657411=/tmp/go-build -gno-record-gcc-switches'
28,29c28,29
< GOMOD='/home/doron/repos/pistol/go.mod'
< GOMODCACHE='/home/doron/.go/pkg/mod'
---
> GOMOD='/home/ysun/Workspace/rfm/go.mod'
> GOMODCACHE='/home/ysun/.cache/go/pkg/mod'
33c33
< GOPATH='/home/doron/.go'
---
> GOPATH='/home/ysun/.local/share/go'
36c36
< GOROOT='/nix/store/33fw5m31lfcnk4ff2f0df7j2bxnh8lgk-go-1.26.3/share/go'
---
> GOROOT='/nix/store/dimnagks1qsp7180yw74z0npp7z2ihs3-go-1.26.2/share/go'
39c39
< GOTELEMETRYDIR='/home/doron/.config/go/telemetry'
---
> GOTELEMETRYDIR='/home/ysun/.config/go/telemetry'
42c42
< GOTOOLDIR='/nix/store/33fw5m31lfcnk4ff2f0df7j2bxnh8lgk-go-1.26.3/share/go/pkg/tool/linux_amd64'
---
> GOTOOLDIR='/nix/store/dimnagks1qsp7180yw74z0npp7z2ihs3-go-1.26.2/share/go/pkg/tool/linux_amd64'
44c44
< GOVERSION='go1.26.3'
---
> GOVERSION='go1.26.2'
1 Like

I cloned you repo and was able to run:

nix develop
go mod tidy

Which downloaded a bunch of dependencies but that was it. No errors.

Building does not work however but it does not seem to be related to you errors above.

go build cmd/pistol/main.go 
# command-line-arguments
cmd/pistol/main.go:49:24: undefined: GetDbPath

Also running the following works as well so I have no clue why it does not work for you.

GOPATH=/tmp/go go mod tidy
1 Like

The README and the Makefile try to point out to use go build ./cmd/pistol. Not go build ./cmd/pistol/main.go.

That worked! This led me to sudo rm -rf ~/.cache/go-build ~/.cache/goimport, which solved the issue also with my default GOPATH=$HOME/.go. Not a Nix specific issue at all.

2 Likes