go: cmd/go: "cannot find module for path"

What did you do?

First , I cleaned $GOPATH/pkg/mod ,

then I wrote a program under ~/testgo/main.go

package main

import "github.com/sirupsen/logrus"

func main() {
	logrus.Infoln("hello world")
}

and then I typed cmmand: go mod init testgo on then same directory. And the go.mod file is:

module testgo

What did you expect to see?

build success without any error.

What did you see instead?

it build failed with output as below:

go: finding github.com/sirupsen/logrus v1.0.6
go: downloading github.com/sirupsen/logrus v1.0.6
go: finding golang.org/x/sys/unix latest
go: finding golang.org/x/crypto/ssh/terminal latest
go: finding golang.org/x/sys latest
go: downloading golang.org/x/sys v0.0.0-20180824143301-4910a1d54f87
go: finding golang.org/x/crypto/ssh latest
go: finding golang.org/x/crypto latest
build testgo: cannot find module for path golang.org/x/crypto/ssh/terminal

and now the go.mod file is:

module testgo

require (
	github.com/sirupsen/logrus v1.0.6
	golang.org/x/sys v0.0.0-20180824143301-4910a1d54f87 // indirect
)

until I add all of cannot find modules to go.mod by myself .

More infomation

I’m in China but I had set the https_proxy and http_proxy, so I can visit google.com and golang.org.

The error module is not always the golang.org/x/crypto, it say sometimes golang/x/sys or golang/x/net

System details

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/anjiawei/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/anjiawei/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/anjiawei/testgo/go.mod"
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-build193967317=/tmp/go-build -gno-record-gcc-switches"

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 4
  • Comments: 21 (12 by maintainers)

Most upvoted comments

Closing this as a duplicate of #26794: the cases that are solved by clearing the module cache (go clean -modcache) are likely explained by it. If you can reproduce these symptoms with sequential go commands on a clean cache, please file a new issue.

I was having this issue. I solved it by deleting all my $GOPATH/pkg/mod directory and downloading everything again. FYI: This issue happened after I run go mod init... in the package and it copied my deps from Godeps (not sure if it has any relation)

I was having this issue. I solved it by deleting all my $GOPATH/pkg/mod directory and downloading everything again. FYI: This issue happened after I run go mod init... in the package and it copied my deps from Godeps (not sure if it has any relation)

can confirm that clearing the $GOPATH/pkg “solves” the issue. now sure if this is related but i noticed that there were a few write protected files listed and i had to force remove them.

For me the error occurs when I run go build from within the built-in terminal in vscode but not from within Terminal. Unless vscode is running another instance of the go command, I am only invoking it once.

I am using local package dependency. All packages (including this package main) are in my GOPATH and I have GO111MODULE=on.

go version go1.11.1 darwin/amd64 In vscode,

go build -v -x
WORK=/var/folders/kz/fc7nstbx16q2gvb1w6rry8cm0000gn/T/go-build516570391
# /Users/salah/Dropbox/code/go/pkg/mod/cache/vcs/208f2541fd98099ee44054de3f910ce8801df288c3fc3b33470badade392c02b for git2 https://github.com/drgo/core
cd /Users/salah/Dropbox/code/go/pkg/mod/cache/vcs/208f2541fd98099ee44054de3f910ce8801df288c3fc3b33470badade392c02b; git ls-remote -q https://github.com/drgo/core
0.302s # cd /Users/salah/Dropbox/code/go/pkg/mod/cache/vcs/208f2541fd98099ee44054de3f910ce8801df288c3fc3b33470badade392c02b; git ls-remote -q https://github.com/drgo/core
go: finding github.com/drgo/core/cache latest
cd /Users/salah/Dropbox/code/go/pkg/mod/cache/vcs/208f2541fd98099ee44054de3f910ce8801df288c3fc3b33470badade392c02b; git -c log.showsignature=false log -n1 '--format=format:%H %ct %D' b9476d56599c7f9df52c80dbd6b989d7bf5263ed
0.010s # cd /Users/salah/Dropbox/code/go/pkg/mod/cache/vcs/208f2541fd98099ee44054de3f910ce8801df288c3fc3b33470badade392c02b; git -c log.showsignature=false log -n1 '--format=format:%H %ct %D' b9476d56599c7f9df52c80dbd6b989d7bf5263ed
cd /Users/salah/Dropbox/code/go/pkg/mod/cache/vcs/208f2541fd98099ee44054de3f910ce8801df288c3fc3b33470badade392c02b; git tag -l
0.008s # cd /Users/salah/Dropbox/code/go/pkg/mod/cache/vcs/208f2541fd98099ee44054de3f910ce8801df288c3fc3b33470badade392c02b; git tag -l
cd /Users/salah/Dropbox/code/go/pkg/mod/cache/vcs/208f2541fd98099ee44054de3f910ce8801df288c3fc3b33470badade392c02b; git -c log.showsignature=false log -n1 '--format=format:%H %ct %D' b9476d56599c
0.009s # cd /Users/salah/Dropbox/code/go/pkg/mod/cache/vcs/208f2541fd98099ee44054de3f910ce8801df288c3fc3b33470badade392c02b; git -c log.showsignature=false log -n1 '--format=format:%H %ct %D' b9476d56599c
cd /Users/salah/Dropbox/code/go/pkg/mod/cache/vcs/208f2541fd98099ee44054de3f910ce8801df288c3fc3b33470badade392c02b; git cat-file blob b9476d56599c7f9df52c80dbd6b989d7bf5263ed:cache/go.mod
0.009s # cd /Users/salah/Dropbox/code/go/pkg/mod/cache/vcs/208f2541fd98099ee44054de3f910ce8801df288c3fc3b33470badade392c02b; git cat-file blob b9476d56599c7f9df52c80dbd6b989d7bf5263ed:cache/go.mod
go: finding github.com/drgo/core latest
cd /Users/salah/Dropbox/code/go/pkg/mod/cache/vcs/208f2541fd98099ee44054de3f910ce8801df288c3fc3b33470badade392c02b; git cat-file blob b9476d56599c7f9df52c80dbd6b989d7bf5263ed:go.mod
0.009s # cd /Users/salah/Dropbox/code/go/pkg/mod/cache/vcs/208f2541fd98099ee44054de3f910ce8801df288c3fc3b33470badade392c02b; git cat-file blob b9476d56599c7f9df52c80dbd6b989d7bf5263ed:go.mod
Fetching https://github.com?go-get=1
Parsing meta tags from https://github.com?go-get=1 (status code 200)
build github.com/drgo/web: cannot find module for path github.com/drgo/core/cache

in Terminal:

go build -v -x
WORK=/var/folders/kz/fc7nstbx16q2gvb1w6rry8cm0000gn/T/go-build164987806