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: go build -mod=mod
with no go.mod erroneously resolves dependencies
#57768
Comments
/cc @bcmills |
I, too, would not have expected that command to work. 😅 @craig65535, I'm curious: why |
|
apparently this ( |
This is indeed a bug. We're supposed to avoid resolving missing imports if we don't have a module root: However, in Go 1.17 (for module graph pruning) we started preloading root modules to maintain the graph pruning invariants: Probably that if errors.As(err, &missing) && ld.ResolveMissingImports && (HasModRoot() || allowMissingModuleImports) { |
go build -mod=mod
with no go.mod erroneously resolves dependencies
Change https://go.dev/cl/536416 mentions this issue: |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?darwin/arm64
What did you do?
I noticed I can build an executable from a bare directory (no go.mod) with
go build -mod=mod
:go build -mod=mod -o xyz.exe github.com/some/go/tool
This does not work without
-mod=mod
:no required module provides package github.com/some/go/tool: go.mod file not found in current directory or any parent directory; see 'go help modules'
.At https://go.dev/ref/mod#build-commands I can see the following for
-mod=mod
:And,
It is finding the module providing a missing package, but it's not updating go.mod (there isn't any), and it's not spelled out in the documentation which go.mod it's using in the first place.
I asked about this on stackoverflow, and someone suggested that he would never have expected this to work and it might be a bug. I find this useful and I'd like to retain this behaviour, but would like to see more clarity in the documentation.
What did you expect to see?
Documentation about this use case
What did you see instead?
No documentation about this use case
The text was updated successfully, but these errors were encountered: