-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: build fails if filename is provided #26798
Comments
The go build command's arguments are interpreted only as packages, not files. You are asking to build the package "main.go", and there is no such package. See the output of "go help build", which begins:
|
Our Makefiles have been building using the above syntax for years. I'll fix them up to be more correct. This change in behavior, even though more correct, might want to be called out in the release notes. There may be other teams using go build incorrectly as well. |
It also fails when using a package name
|
CC @bcmills This works differently in module mode vs GOPATH mode
|
Not sure quite what's happening here, but it sounds like there has been a change in behavior. Re-opening. |
Similarly executing
However |
This is a departure from previous documented behavior if we cannot specify a list of .go files to "go build". The output of "go help build" continues:
|
This has the same underlying cause as #26722; so closing as a duplicate. I've confirmed that the fix in https://go-review.googlesource.com/c/go/+/127796 for that issue fixes this case:
gives:
whereas on tip (5a720d2) this fails. |
With go 1.10.3 and vgo devel +1b870077c8, this error occurs: build main: cannot find module for path main Ref golang/go#26798
With go 1.10.3 and vgo devel +1b870077c8, this error occurs: build main: cannot find module for path main Ref golang/go#26798
What version of Go are you using (
go version
)?go1.11beta3
Does this issue reproduce with the latest release?
Doesn't repro on go1.10 or go1.11beta2
What operating system and processor architecture are you using (
go env
)?GOARCH="amd64"
GOOS="darwin"
What did you do?
Made single
main.go
hello world app with one linego.mod
fileRan
go build -o bin/mod-test main.go
What did you expect to see?
Successful build
What did you see instead?
Build error:
build main: cannot find module for path main
If I run the build without the filename
go build -o bin/mod-test
it works fineThis is a change from previous versions of Go.
The text was updated successfully, but these errors were encountered: