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

"missing dot in first path element" error for imports from vendor #35048

Closed
xyt0056 opened this issue Oct 21, 2019 · 9 comments
Closed

"missing dot in first path element" error for imports from vendor #35048

xyt0056 opened this issue Oct 21, 2019 · 9 comments
Labels
FrozenDueToAge modules WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@xyt0056
Copy link

xyt0056 commented Oct 21, 2019

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?

@bcmills
Copy link
Contributor

bcmills commented Oct 21, 2019

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?

@bcmills
Copy link
Contributor

bcmills commented Oct 21, 2019

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.

@bcmills bcmills added modules WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Oct 21, 2019
@xyt0056
Copy link
Author

xyt0056 commented Oct 21, 2019

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/....")

@bcmills
Copy link
Contributor

bcmills commented Oct 21, 2019

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

Yep, that's the most robust fix.

@bcmills
Copy link
Contributor

bcmills commented Oct 22, 2019

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

@bcmills bcmills closed this as completed Oct 22, 2019
@daaru00

This comment has been minimized.

@bcmills

This comment has been minimized.

@maxprkr
Copy link

maxprkr commented Jul 3, 2020

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.

@Addyvan
Copy link

Addyvan commented Oct 24, 2020

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.

nars1 added a commit to YottaDB/YDBOcto that referenced this issue Jun 9, 2021
…g Go Modules instead of GOPATH by default

* After a system upgrade from `Ubuntu 20.10` to `Ubuntu 21.04`, we noticed an in-house system started failing
  bats tests that used the `go` utility. An example failure symptom is the following.

  ```sh
  $ bats --tap -f TPGC001 bats_tests/test_psql_go_connection.bats
  1..1
  not ok 1 TPGC001 : fetch column data types
  .
  .
  # > go get: malformed module path "get_column_information": missing dot in first path element
  ```

* Thanks to golang/go#35048 (comment), I found the issue and workaround.
  I made a change to do the following before the `go get` that is done in the `run_go()` framework function
  in `tests/test_helpers.bash.in` and `go` related bats tests started working fine then on.

  ```sh
  export GO111MODULE=off
  ```

* https://dev.to/maelvls/why-is-go111module-everywhere-and-everything-about-go-modules-24k discusses this
  issue in detail. Pasted below is the relevant text from there.

  ```
  GO111MODULE with Go 1.16
  ------------------------
  As of Go 1.16, the default behavior is GO111MODULE=on, meaning that if you want to keep using the old
  GOPATH way, you will have to force Go not to use the Go Modules feature:

  export GO111MODULE=off
  ```

* This is exactly what was done at https://gitlab.com/YottaDB/DB/YDBTest/-/merge_requests/1129/diffs too.

* We will need to worry about this when Go 1.17 comes out and everything starts only using `Go Modules`.
  But until then this workaround is good enough.
@golang golang locked and limited conversation to collaborators Oct 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge modules WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

6 participants