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: malformed module path "xxxx/xxxx/uuid" missing dot in first path element when migrating from GOPATH based dep to go mod #35020

Closed
AyushG3112 opened this issue Oct 20, 2019 · 4 comments

Comments

@AyushG3112
Copy link

@AyushG3112 AyushG3112 commented Oct 20, 2019

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

$ go version
1.13.3

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="/home/ayush/projects/gojects/bin"
GOCACHE="/home/ayush/.cache/go-build"
GOENV="/home/ayush/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/ayush/projects/gojects"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build570102704=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I had a folder structure as follows:

GOPATH
+---src
     +--- my-api-server
           +--- my-auth-server
                 +--- main.go
           +--- my-utils
                 +--- uuid
                       +--- uuid.go

my-auth-server uses my-api-server/my-utils/uuid as a depenency

Now, when I used the GOPATH based module system, this worked fine. But when using go modules, when I run go run main.go in my-auth-server it returned error:

build command-line-arguments: cannot load my-api-server/my-utils/uuid: malformed module path "my-api-server/my-utils/uuid": missing dot in first path element

What did you expect to see?

My project should have been started successfully

What did you see instead?

build command-line-arguments: cannot load my-api-server/my-utils/uuid: malformed module path "my-api-server/my-utils/uuid": missing dot in first path element
@AyushG3112

This comment has been minimized.

Copy link
Author

@AyushG3112 AyushG3112 commented Oct 20, 2019

Also, I tried moving my-utils inside my-auth-server, but as a library, my-utils will be used in multiple places.

Now, my-utils also has a go.mod, but that contains a module declaration.
If I place it in my-auth-server, the module path becomes my-api-server/my-auth-server/my-utils

If I have 2 servers,

  • my-auth-server
  • my-session-server

I cannot place my-utils inside both because there can only be one module declaration per go.mod.

Any help in solving this would also be appreciated.

@dmitshur

This comment has been minimized.

Copy link
Member

@dmitshur dmitshur commented Oct 21, 2019

There is currently a requirement that the module path must have a dot in the first path element.

Any help in solving this would also be appreciated.

The only change you have to make is add a dot to the first element of the module path. If you don't intend to make the module available on the internet, you can use a reserved TLD like .localhost that signifies that. For example, the following module path would work:

my-api-server.localhost/my-utils/uuid

You may also find the https://blog.golang.org/migrating-to-go-modules blog post helpful.

/cc @jayconrod @bcmills

@dmitshur dmitshur changed the title malformed module path "xxxx/xxxx/uuid" missing dot in first path element when migrating from GOPATH based dep to go mod cmd/go: malformed module path "xxxx/xxxx/uuid" missing dot in first path element when migrating from GOPATH based dep to go mod Oct 21, 2019
@bcmills

This comment has been minimized.

Copy link
Member

@bcmills bcmills commented Oct 21, 2019

The only change you have to make is add a dot to the first element of the module path.

Or, as an alternative, if both components are in the same version-control repo, you can place a single go.mod file at GOPATH/src/my-api-server/go.mod instead of splitting up the repo into smaller modules.

Or, you can use a replace directive to retarget the locations of the modules and avoid a remote lookup.

Regardless, the best approach is to choose a domain name or prefix under your control for the import path, as @dmitshur suggests. (See #32819.)

@bcmills

This comment has been minimized.

Copy link
Member

@bcmills bcmills commented Oct 21, 2019

Duplicate of #32819

@bcmills bcmills marked this as a duplicate of #32819 Oct 21, 2019
@bcmills bcmills closed this Oct 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.