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)
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 sequentialgo
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)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,
in Terminal: