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: no required module provides package main.go; to add it #48117

Open
korzhao opened this issue Sep 1, 2021 · 4 comments
Open

cmd/go: no required module provides package main.go; to add it #48117

korzhao opened this issue Sep 1, 2021 · 4 comments
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@korzhao
Copy link
Contributor

korzhao commented Sep 1, 2021

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

$ go version
go1.17

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="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/kezhao/Library/Caches/go-build"
GOENV="/Users/kezhao/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/kezhao/go/pkg/mod"
GONOPROXY="git.code.oa.com,git.woa.com"
GONOSUMDB="git.code.oa.com,git.woa.com"
GOOS="darwin"
GOPATH="/Users/kezhao/go"
GOPRIVATE="git.code.oa.com,git.woa.com"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/kezhao/google/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/kezhao/google/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="devel go1.18-8dd1dd5b7f Sun Aug 29 06:19:02 2021 +0800"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/kezhao/go/src/apnstest/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 -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/2g/yv3ln7wj5vbdtwfj0js10krh0000gn/T/go-build1388352891=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

rm main.go
go build main.go

What did you expect to see?

stat main.go: no such file or directory

What did you see instead?

$ go build main.go
no required module provides package main.go; to add it:
go get main.go

$ go get main.go
go get main.go: arguments must be package or module paths

@jayconrod jayconrod added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Sep 1, 2021
@jayconrod jayconrod added this to the Unplanned milestone Sep 1, 2021
@jayconrod
Copy link
Contributor

cc @bcmills @matloob

This is a consequence of #34653, so maybe it's working as intended. We treat an argument ending with .go as a package path, not a source file, if the source file with that name doesn't exist. That's necessary for github.com/nats/nats.go.

@bcmills
Copy link
Contributor

bcmills commented Sep 1, 2021

The error message from go build is not wrong: main.go could be either a file, or a package (perhaps one provided by a local proxy, workspace, or replace directive).

That said, we should probably not suggest go get on a path ending in .go (since the cause is more likely to be a missing file than a missing package), and we probably should mention no such file: there are two possible interpretations of the argument, and we should explain why both interpretations fail.

@bcmills
Copy link
Contributor

bcmills commented Sep 1, 2021

The error message from go get main.go does look outright wrong: go get should not assume that paths ending in .go are file paths, and AFAICT main.go is also valid module path. So it's fine for go get main.go to report that main.go does not exist as a file, but it also ought to see if a module main.go exists.

@jayconrod
Copy link
Contributor

PackagesAndErrors only calls GoFilesPackage if main.go exists; otherwise it treats it like a package path, which I think is correct.

Maybe ImportMissingError just needs a special case for paths ending with .go?

@bcmills bcmills added GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Feb 16, 2023
@bcmills bcmills modified the milestones: Unplanned, Backlog Feb 16, 2023
@gopherbot gopherbot removed the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Feb 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go 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

4 participants