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: when 'go build' run in directory with go.mod and no .go files: "cannot find module for path ." #35414

Closed
GingerMoon opened this issue Nov 7, 2019 · 4 comments
Assignees
Milestone

Comments

@GingerMoon
Copy link

@GingerMoon GingerMoon commented Nov 7, 2019

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

go version go1.12.2 linux/amd64

Does this issue reproduce with the latest release?

What operating system and processor architecture are you using (go env)?

go env Output
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"

What did you do?

I want to put several common modules into one repo.
So the repo layout looks like below:

common-modules/
        |-- module1/
                |-- *.go files
        |-- module2/
                |-- *.go files
        go.mod

The go.mod file looks like:

module company1.com/common-modules

go 1.12

Run "go build" under directory common-modules.

What did you expect to see?

No error is returned.

What did you see instead?

If I run "go build" under directory common-modules, error returns:
can't load package: package company1.com/common-modules: unknown import path "company1.com/common-modules": cannot find module providing package company1.com/common-modules

@ianlancetaylor ianlancetaylor changed the title Run "go build" in an directory which contains only go.mod (no other go files) returns error: can't load package unknown import path cmd/go: Run "go build" in an directory which contains only go.mod (no other go files) returns error: can't load package unknown import path Nov 7, 2019
@ianlancetaylor ianlancetaylor added this to the Go1.14 milestone Nov 7, 2019
@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Nov 7, 2019

@bcmills

This comment has been minimized.

Copy link
Member

@bcmills bcmills commented Nov 8, 2019

go version go1.12.2

I believe we fixed some related bugs in 1.13. What happens if you try this with the current release (Go 1.13.4)?

@GingerMoon

This comment has been minimized.

Copy link
Author

@GingerMoon GingerMoon commented Nov 11, 2019

Hi @bcmills
The result is the same for 1.13.4:

[myname@mycompany myproject]$ ll
total 4
drwxrwxr-x. 5 myname myname 100 Nov 11 10:40 fe3
-rw-rw-r--. 1 myname myname 47 Nov 11 10:40 go.mod
drwxrwxr-x. 6 myname myname 107 Nov 7 20:04 ll3
[myname@mycompany myproject]$ go build
build .: cannot find module for path .
[myname@mycompany myproject]$ cat go.mod
module git.mycompany.com/cloud/myproject

go 1.13
[myname@mycompany myproject]$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/myname/.cache/go-build"
GOENV="/home/myname/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/myname/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/gorootpath/go-1.13.4"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/gorootpath/go-1.13.4/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/myname/myproject/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-build343362267=/tmp/go-build -gno-record-gcc-switches"
[myname@mycompany myproject]$ go build
build .: cannot find module for path .

@jayconrod jayconrod changed the title cmd/go: Run "go build" in an directory which contains only go.mod (no other go files) returns error: can't load package unknown import path cmd/go: when 'go build' run in directory with go.mod and no .go files: "cannot find module for path ." Nov 11, 2019
@jayconrod jayconrod self-assigned this Nov 13, 2019
@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Nov 13, 2019

Change https://golang.org/cl/206902 mentions this issue: cmd/go: fix error for empty packages referenced with relative paths

@gopherbot gopherbot closed this in 608b94b Nov 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.