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
Labels
FrozenDueToAge modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@GingerMoon
Copy link

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 modules NeedsFix The path to resolution is known, but the work has not been done. labels Nov 7, 2019
@ianlancetaylor ianlancetaylor added this to the Go1.14 milestone Nov 7, 2019
@ianlancetaylor
Copy link
Contributor

CC @bcmills @jayconrod

@bcmills
Copy link
Contributor

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)?

@bcmills bcmills added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Nov 8, 2019
@gopherbot gopherbot removed the NeedsFix The path to resolution is known, but the work has not been done. label Nov 8, 2019
@GingerMoon
Copy link
Author

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 removed the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Nov 11, 2019
@jayconrod jayconrod self-assigned this Nov 13, 2019
@gopherbot
Copy link

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants