Go: "missing dot in first path element" error for imports from vendor

Created on 21 Oct 2019  路  9Comments  路  Source: golang/go

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

$ go version
go1.13

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="/Users/me/go/bin"
GOCACHE="/Users/me/Library/Caches/go-build"
GOENV="/Users/me/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY="none"
GONOSUMDB="code.corp.internal"
GOOS="darwin"
GOPATH="/Users/me/go-code"
GOPRIVATE="code.corp.internal"
GOPROXY="https://proxy.corpinternal.com"
GOROOT="/private/var/tmp/_bazel_me/cde87e3334239cff91d2a561f734e9a6/external/go_sdk"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/private/var/tmp/_bazel_me/cde87e3334239cff91d2a561f734e9a6/external/go_sdk/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/nn/f16l5j1j2f14ctsnkk305lf00000gp/T/go-build790203101=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?


upgrade to go1.13 and run go mod tidy

What did you expect to see?

finish successfully

What did you see instead?

missing dot in first path element

in go1.12, we have generated code(mocks etc.) in vendor folder and the code itself imports it by relative path in vendor.
here's our code structure

gopath/
    src/
        vendor/
            mock1/
        code.corp.internal/
            go.mod
            go.sum
            repo1/
            repo2/

in the code, we import it as import mock1/..., and this gives us error of "missing dot in first path element". What is the recommended way in this case?

WaitingForInfo modules

All 9 comments

The missing dot in first path element error only occurs in module mode, but the go env output you have attached indicates that you are not in module mode.

Was the go env output produced from the same working directory as the go command that produced the reported error?

Note that module mode does not support relative imports, nor does it use GOPATH/src/vendor. Most likely this is a byproduct of the change in behavior of GO111MODULE=auto in 1.13, as described in https://golang.org/doc/go1.13#modules: it now engages module mode in GOPATH/src by default whenever there is a go.mod file in a parent directory of the current working directory.

Note that module mode does not support relative imports, nor does it use GOPATH/src/vendor. Most likely this is a byproduct of the change in behavior of GO111MODULE=auto in 1.13, as described in https://golang.org/doc/go1.13#modules: it now engages module mode in GOPATH/src by default whenever there is a go.mod file in a parent directory of the current working directory.

We have explicitly set GO111MODULE=on.
According to this, do you suggest we change the import path to monorepo module + relative path? (import "code.corp.internal/mock1/....")

import "code.corp.internal/mock1/...."

Yep, that's the most robust fix.

I don't think there's anything more to be done here, so closing.

Have same issue with version go version go1.14 linux/amd64

Here my go.mod:

module docker

go 1.14

require (
    github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
    github.com/urfave/cli/v2 v2.2.0
    dockerlib v0.0.0
)

replace (
    dockerlib v0.0.0 => "../../lib/docker"
)

when try to run "go build"

go: [email protected] requires
        [email protected]: malformed module path "dockerlib": missing dot in first path element

don't know ehere the error is, dot is in first element path!

Tried also with:

require (
    github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
    github.com/urfave/cli/v2 v2.2.0
    ../../lib/docker v0.0.0
)

but an other strange error appear:

go: [email protected] requires
        ../../lib/[email protected]: malformed module path "../../lib/docker": invalid path element "..

when ../ is a valid path element..

@daaru00, this issue is closed. If you are experiencing an issue that you believe to be a defect in the go command or its documentation, please file a new issue and fill out the complete issue template.

Otherwise (for questions about how to use Go, rather than a feature request or defect report), there are many other methods to get help if you're still looking for answers:

Thanks

in linux type:

<(prompt)>export GO111MODULE=off

and then build & run your project

it is related to the change of importing modules in (and after) go version 1.11
it's a pity that the go's error message for this common error is so obscure, and doesn't hint any solution.

in linux type:

<(prompt)>export GO111MODULE=off

and then build & run your project

it is related to the change of importing modules in (and after) go version 1.11
it's a pity that the go's error message for this common error is so obscure, and doesn't hint any solution.

Running this lead me to a far more intelligible error message:

main.go:3:8: cannot find package "core/grid" in any of:
        /usr/local/go/src/core/grid (from $GOROOT)
        /go/src/src/core/grid (from $GOPATH)

I was able to fix my path issue, thanks.

Was this page helpful?
0 / 5 - 0 ratings