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: needs a better error than "missing dot in first path element" when GOROOT is set incorrectly #34184

Closed
damozhiying opened this issue Sep 9, 2019 · 50 comments
Labels
help wanted modules NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@damozhiying
Copy link

what's wrong about the error
build command-line-arguments: cannot load golang_org/x/crypto/chacha20poly1305: malformed module path "golang_org/x/crypto/chacha20poly1305": missing dot in first path element
2019-09-09 15-56-23屏幕截图

@damozhiying
Copy link
Author

2019-09-09 16-00-15屏幕截图

@ALTree ALTree added the modules label Sep 9, 2019
@ALTree ALTree changed the title missing dot in first path element cmd/go: missing dot in first path element Sep 9, 2019
@ALTree ALTree added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 9, 2019
@antong
Copy link
Contributor

antong commented Sep 9, 2019

I typed in the code in the screenshot and ran the code without any error with the same go version you have. @damozhiying , could you include all the information that is in the issue template, including go env output. Also, it would be much easier if you would post as text and not images.

@katcipis
Copy link

katcipis commented Sep 9, 2019

Im getting a similar behaviour, the code is not open source and I haven't isolated the problem yet, but the same code that was working 5 minutes ago with Go 1.12.9 now gives this error with 1.13. Running go mod vendor results in:

github.com/prv/store imports
	cloud.google.com/go/datastore imports
	google.golang.org/api/option imports
	golang.org/x/oauth2/google imports
	golang.org/x/oauth2/jws imports
	crypto: malformed module path "crypto": missing dot in first path element
github.com/prv/store imports
	cloud.google.com/go/datastore imports
	google.golang.org/api/option imports
	golang.org/x/oauth2/google imports
	golang.org/x/oauth2/jws imports
	crypto/sha256: malformed module path "crypto/sha256": missing dot in first path element
github.com/prv/store imports
	cloud.google.com/go/datastore imports
	google.golang.org/api/transport/grpc imports
	go.opencensus.io/plugin/ocgrpc imports
	go.opencensus.io/tag imports
	runtime/pprof: malformed module path "runtime/pprof": missing dot in first path element
github.com/prv/store imports
	cloud.google.com/go/datastore imports
	google.golang.org/grpc imports
	golang.org/x/net/http2 imports
	golang.org/x/net/idna imports
	golang.org/x/text/unicode/bidi imports
	container/list: malformed module path "container/list": missing dot in first path element

go test ./... and go get ./...:

build github.com/prv/cmd/prv: cannot load bufio: malformed module path "bufio": missing dot in first path element

OS:

uname -a     
Darwin macbook 18.7.0 Darwin Kernel Version 18.7.0: Tue Aug 20 16:57:14 PDT 2019; root:xnu-4903.271.2~2/RELEASE_X86_64 x86_64

Go:

go version
go version go1.13 darwin/amd64

Got suspicious of a recent change that I made in my environment, which is setting GOPATH. unset GOPATH and now everything works. The odd thing is that the project is outside the GOPATH and has go.mod, everything seems to be on module mode, but if there is a GOPATH set in my env the go commands fails with these odd error messages

@bcmills
Copy link
Contributor

bcmills commented Sep 10, 2019

@katcipis, @damozhiying: as @antong notes, we need concrete steps to reproduce the problem.

Please fill out the complete issue template, and provide specific commands — as text that we can easily copy and paste — that we can run to reproduce the problem.

@bcmills bcmills added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Sep 10, 2019
@maniLonkar
Copy link

@bcmills
Copy link
Contributor

bcmills commented Sep 12, 2019

@maniLonkar, brew install go is not a command supported by the Go team. If you are observing this issue, please provide steps to reproduce it either starting from source or using the official distribution from https://golang.org/dl.

@deavid
Copy link

deavid commented Sep 14, 2019

Just ran on the same problem while doing the Go tour in spanish:
https://gotour-es.appspot.com/#45

build command-line-arguments: cannot load tour/wc: malformed module path "tour/wc": missing dot in first path element

The english version seems corrected:
https://tour.golang.org/moretypes/23

Something has changed recently

@amossc
Copy link

amossc commented Sep 16, 2019

I hit this error when following the instructions to install gopls:

GO111MODULE=on go get golang.org/x/tools/gopls@latest
go: finding golang.org/x/tools latest
go: finding golang.org/x/tools/gopls v0.1.5
go: downloading golang.org/x/tools v0.0.0-20190916020655-1ccc110ba9df
go: downloading golang.org/x/tools/gopls v0.1.5
go: extracting golang.org/x/tools v0.0.0-20190916020655-1ccc110ba9df
go: extracting golang.org/x/tools/gopls v0.1.5
go: downloading golang.org/x/tools v0.0.0-20190911225940-c7d52e45e2f2
go: extracting golang.org/x/tools v0.0.0-20190911225940-c7d52e45e2f2
go: downloading golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7
go: downloading golang.org/x/sync v0.0.0-20190423024810-112230192c58
go: extracting golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7
go: extracting golang.org/x/sync v0.0.0-20190423024810-112230192c58
go: finding golang.org/x/tools v0.0.0-20190911225940-c7d52e45e2f2
build golang.org/x/tools/gopls: cannot load bufio: malformed module path "bufio": missing dot in first path element
$ go version
go version go1.13 darwin/amd64

Instructions taken from: https://github.com/golang/go/wiki/gopls

@bcmills
Copy link
Contributor

bcmills commented Sep 16, 2019

@amossc, please include the output of go env.

Are you using the official Go distribution, or something installed via brew?

@bcmills bcmills added WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. and removed WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Sep 16, 2019
@echoface

This comment has been minimized.

@me440378

This comment has been minimized.

@me440378
Copy link

I found that if you set the GOROOT right,the problem would be solved.

@ALTree
Copy link
Member

ALTree commented Sep 18, 2019

@bcmills In #34245 (dup of this one) @maniLonkar reported that Installing Go from brew appears to fix the issue, so I'm guessing that this only hits people that installed Go from the official distribution. In that issue, the output of go env was also pasted.

@huangong @InfernoEmperor just writing that you have the same issue doesn't help much. Can you please 1) write here how you installed Go 2) paste here the output of Go env 3) provide steps to reproduce the issue (i.e. a sequence of terminal commands that trigger the error). Thanks.

@wanghaolonggit
Copy link

怎么解决的?

@me440378
Copy link

怎么解决的?

我把GOROOT的环境变量重新设置为了GO的安装路径就解决了,如果你的GOROOT环境变量的内容不是GO的安装路径可以试试

@mjyuser
Copy link

mjyuser commented Sep 18, 2019

when I use /usr/local/go/bin/go1.13 env -w GOPROXY=https://goproxy.cn,direct && /usr/local/go/bin/go1.13 env -w GOPRIVATE=git.kuainiujinke.com && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 /usr/local/go/bin/go1.13 build -o feature --tags release main.go in jenkins, occur this error, the machine conf version is Linux version 4.9.87-linuxkit-aufs (root@95fa5ec30613) (gcc version 6.4.0 (Alpine 6.4.0) ) #1 SMP Wed Mar 14 15:12:16 UTC 2018, go version go1.13 linux/amd64

@bcmills
Copy link
Contributor

bcmills commented Sep 18, 2019

@me440378, @wanghaolonggit: it is usually best to leave the GOROOT environment variable unset. It has not been necessary for a long time — perhaps since Go 1.0?

(See https://dave.cheney.net/2013/06/14/you-dont-need-to-set-goroot-really.)

@bcmills
Copy link
Contributor

bcmills commented Sep 18, 2019

@mjyuser, please provide steps to reproduce the problem without using Jenkins. (Given the information that @me440378 provided, it probably has something to do with the process's environment.)

@me440378
Copy link

@mjyuser, please provide steps to reproduce the problem without using Jenkins. (Given the information that @me440378 provided, it probably has something to do with the process's environment.)

As you said, it may not be related to GOROOT? I started by making a soft link file of go executable file into the bin directory of my home directory, set the home directory to GOROOT, and set GOBIN to GOROOT/bin. After that, I got into trouble. This problem is solved when I reset GOROOT to the GO installation directory.

@doug4j
Copy link

doug4j commented Sep 18, 2019

I was getting missing dot in first path element error but then discovered the module name in my go.mod when it was module github.com/doug4j/templ (note: the user name should be doug4j NOT doug4 I got the following error on go mod tidy:

github.com/doug4/templ/go/cmd/templ imports
	github.com/doug4j/templ/go/cmd/templ/cmd: module github.com/doug4j/templ@latest (v0.0.0-20180620223934-65a7663df59d) found, but does not contain package github.com/doug4j/templ/go/cmd/templ/cmd
github.com/doug4/templ/go/templcore/tealegxlsx imports
	github.com/doug4j/templ/go/templcore imports
	simpledateformat: malformed module path "simpledateformat": missing dot in first path element
github.com/doug4/templ/go/templcore/tealegxlsx imports
	github.com/doug4j/templ/go/templcore imports
	templ/go/logr: malformed module path "templ/go/logr": missing dot in first path element
github.com/doug4/templ/go/templcore/tealegxlsx imports
	github.com/doug4j/templ/go/templcore imports
	templ/go/templapi: malformed module path "templ/go/templapi": missing dot in first path element
github.com/doug4/templ/go/templcore/tealegxlsx imports
	github.com/doug4j/templ/go/templcore imports
	templ/go/util: malformed module path "templ/go/util": missing dot in first path element

When I put the module name correctly as module github.com/doug4j/templ (with the "j" at the end) all was well.

I didn't have to adjust GOROOT or GOPATH at all.

Just wanted to note this in case it helps someone else.

@mjyuser
Copy link

mjyuser commented Sep 19, 2019

@bcmills my local docker have go1.12.9 and go1.13, when i run build, the error reporting
/usr/local/go/bin/go1.13 env -w GOPRIVATE=git.kuainiujinke.com && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 /usr/local/go/bin/go1.13 build -o feature --tags release main.go

i tried @me440378 method, but no success
image

@mjyuser
Copy link

mjyuser commented Sep 19, 2019

may be the reason for the image, i built a image of centos 7.6 and installed both versions 1.12 and 1.13, the use of image will be abnormal, but when i build an official go:latest image, the process is successful

@amossc
Copy link

amossc commented Sep 20, 2019

@bcmills here is the output of go env. I'm using go installed via brew install go:

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/amos/Library/Caches/go-build"
GOENV="/Users/amos/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY="github.com/SafetyCulture"
GONOSUMDB="github.com/SafetyCulture"
GOOS="darwin"
GOPATH="/Users/amos/casesafe/go"
GOPRIVATE="github.com/SafetyCulture"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.13/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.13/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/wh/s26xk7_1265f4qgkrmkghgsh0000gn/T/go-build836927503=/tmp/go-build -gno-record-gcc-switches -fno-common"

@bcmills
Copy link
Contributor

bcmills commented Sep 20, 2019

@amossc, please try removing the brew-installed Go toolchain and installing from the official distribution (https://golang.org/dl) instead.

The GOROOT="/usr/local/Cellar/go/1.13/libexec" line in your go env output looks suspicious as well — did you set that explicitly?

@bcmills
Copy link
Contributor

bcmills commented Sep 30, 2019

@gustavolopess, setting GOROOT equal to GOPATH is definitely not going to help. GOROOT needs to point to the root of the Go source tree.

In your case, is it possible that gvm build a Go toolchain and then subsequently moved it to a different directory? That would result in an invalid GOROOT being embedded in the binary itself.

@bcmills
Copy link
Contributor

bcmills commented Sep 30, 2019

@xroba, how had you installed the go toolchain on your system?

@bcmills bcmills added WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. and removed WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Sep 30, 2019
@phantomSuying

This comment has been minimized.

@bcmills
Copy link
Contributor

bcmills commented Oct 7, 2019

Nobody seems to be providing information about how the invalid GOROOT was set, but given the seeming diversity of these error reports it seems clear to me that we need a better diagnostic no matter how it happens.

@bcmills bcmills added NeedsFix The path to resolution is known, but the work has not been done. and removed WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Oct 7, 2019
@gopherbot gopherbot removed the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Oct 7, 2019
@bcmills bcmills added help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Oct 7, 2019
@bcmills bcmills added this to the Go1.14 milestone Oct 7, 2019
@gopherbot gopherbot removed the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Oct 7, 2019
@bcmills bcmills changed the title cmd/go: "missing dot in first path element" when GOROOT is set incorrectly cmd/go: needs a better error than "missing dot in first path element" when GOROOT is set incorrectly Oct 7, 2019
@bradwilzon
Copy link

@bcmills how is GOROOT supposed to look? I'm having this problem as well using Goland 2019.2.3 (2019-10-01 build) and/usr/local/Cellar/go/1.13/libexec is the default (and only) option my IDE has for setting GOROOT.

My company machine is managed by some super long running script that we run every once in a while, and that's likely how I upgraded to 1.13. It wouldn't surprise me at all if the script is using brew to install Go. Do you believe installation this way could cause this problem?

@rsc
Copy link
Contributor

rsc commented Oct 8, 2019

Duplicate of #34769.

@rsc rsc closed this as completed Oct 8, 2019
@Mantic
Copy link

Mantic commented Oct 16, 2019

What about windows users? I'm using Windows 10 and git's mingw64 terminal. Everything was working until I rebooted my computer. I have no GOROOT set... If I should set it, what do I set it to?

@bcmills
Copy link
Contributor

bcmills commented Oct 16, 2019

@Mantic, you want go env GOROOT to be the directory above the \bin\ component in the path reported by where go.

@ianlancetaylor
Copy link
Contributor

@Mantic Note that a closed issue is not the best place to ask questions. See https://golang.org/wiki/Questions. Thanks.

@AmitShaul
Copy link

I'm trying to install "google/api/annotations.proto" and keep getting:
go get google/api/annotations.proto: malformed module path "google/api/annotations.proto": missing dot in first path element
I installed go in the recommended way.

when I echo $GOROOT I get an empty result though in my "go env" variables it's set to "/usr/local/go":

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/amit/Library/Caches/go-build"
GOENV="/Users/amit/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/amit/workspace/"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
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"

@lobo-a
Copy link

lobo-a commented Oct 17, 2019

go version go1.13.1 linux/amd64

Environment:
GOROOT=/home/yx/server/go
GOBIN=/home/yx/server/go/bin
GOPATH=/home/yx/goproj
Directory: /home/yx/goproj/src/mysports
Command: /home/yx/server/go/bin/go test -v
Output:
hello.go:4:2: malformed module path "mysports/utils/crypt": missing dot in first path element
Elapsed: 0.098s
Result: Error

/home/yx/goproj/src/mysports
|--hello_test.go
|--hello.go
|--go.mod
|--README.md
|--go.sum
|--utils
| |--crypt
| | |--go.mod
| | |--crypt_test.go
| | |--crypt.go

@bcmills @me440378

go evn seems correct, but it reports an error

@bcmills
Copy link
Contributor

bcmills commented Oct 17, 2019

@AmitShaul @lobo-a, the instances of this error message that you are getting are correct, and are unrelated to GOROOT. See https://blog.golang.org/organizing-go-code#TOC_3..

@eddie-velez
Copy link

I continue to get the same "missing dot" error. Is there an official resolution? Nothing in this chain has helped.

@bcmills
Copy link
Contributor

bcmills commented Oct 18, 2019

@eddie-velez, if the path is something in the standard library, then the problem is almost certainly your GOROOT setting.

If the path is not something in the standard library, then the error message is likely accurate, and you need to choose an import path that belongs to a (local or fetchable) module; see https://blog.golang.org/organizing-go-code#TOC_3..

@jcburley

This comment has been minimized.

@jcburley

This comment has been minimized.

@bcmills

This comment has been minimized.

@bcmills
Copy link
Contributor

bcmills commented Oct 21, 2019

The discussion on this issue seems to be ranging far from the original issue, and we have a new issue filed to track the underlying problem (a less-than-ideal diagnostic when GOROOT is set incorrectly).

If folks are seeing the same issue with the same root cause, please see the tracking issue for that diagnostic.

If folks are seeing the same issue with a different root cause, please try to diagnose it in your code — and if the error message is missing the information you need in order to do that, please open a new issue with a specific code example and layout that reproduces the problem.

@golang golang locked as off-topic and limited conversation to collaborators Oct 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
help wanted modules NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests