-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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: package is replaced but not required #44529
Comments
Try |
It's also worth considering:
|
I think I misdiagnosed my problem. Still investigating it. I'm seeing strange build times and I assumed it was downloading data, but maybe it's just doing some re-builds I'm not expecting. |
Instead, you can add a requirement on a non-existent version while replacing that version:
Adding a replacement, even one without a version on the left side, doesn't automatically add that module to the build list. If it did, the go command would read its |
If you are not using a proxy for the repo in question, that lookup may involve cloning the upstream repo. So that can be a pretty expensive operation. (Note that the official distributions of the If that network lookup fails, then ¹ go/src/cmd/go/internal/modload/import.go Lines 334 to 351 in 7eb31d9
² go/src/cmd/go/internal/modload/query.go Lines 987 to 1000 in 7eb31d9
³ go/src/cmd/go/internal/modload/query.go Lines 1045 to 1062 in 7eb31d9
|
Timed out in state WaitingForInfo. Closing. (I am just a bot, though. Please speak up if this is a mistake or you have the requested information.) |
Dear gopherbot, please can you re-open this issue? I am having this exact same problem when trying to use local code with go version go1.16 Something that used to work no longer works, so I think this is a clear bug! (FYI: ref my "local builds" issue #43829 which details a new "standard" way of working which is the best that we can do for now with modules until it's properly fixed for local code. Sadly, 1.16 seems to have broken even this way of working!) |
retried with go version "go version go1.16.4 linux/amd64", and the same problem exists. However, doing a "mod tidy" works around the issue (presumably by adding a: require _/xxx v0.0.0-00010101000000-000000000000 and then it builds ok (but of course, this step should not be required?...) |
Note: the issue seems to be known: ref: https://stackoverflow.com/questions/66469396/go-module-is-found-and-replaced-but-not-required So my question now @bcmills is: why was this default behavior changed as it now increases the barrier to entry for simple tasks (ie run a simple, formerly quick, test!)? And, it also creates for a really strange and confusing coding experience where you have to look up this issue to simply run a short test of some package: it's not intuitive at all! Before: Now: |
Maybe a simple fix is to change the error message, ie, instead of this (which I knew I didn't want to do):
tell the user that a simple "go mod tidy" would also work (and avoid hitting the network), eg:
` |
Sorry for the multiple comments, but I'm noting these as they occur. @bcmills you said "add new requirements as needed", so this suggests that having a "replace" directive does not imply a "require": my thought would be that if i add a replace directive, it's clearly an indication that I also "require" that same package. Maybe the additional step is that if it's not remote, it's a local dependency and should hence always be added? (I admit I find all of this too confusing!) |
This is working as intended.
About adding |
My problem with "go get" is "go get, on the other hand, will perform a network lookup" (and I'm trying to work 100% locally with no network lookups (hence my preference for "go mod tidy"). Also, can you point me to any information on why the default mode was changed (ie away from -mod=mod which seemed to work ok)? Thanks. |
@marystern Both #40728 was the issue to change the default to |
Thanks @jayconrod , issue #40728 was interesting, and linked to a similar concern to mine over "developer flow/ease" in #44212. Personally, I think this is another one of those "rough edges" that still needs ironing out (getting going in go is proving harder by the release when it should be getting easier!) |
Note that as of Go 1.16 So if you set |
A final note (sorry, I've only just realized this after the issue was closed). The critical thing, in hindsight, was my reading and comprehension of the error message. The message:
is clear, simple English, and hence, sadly failed to shout the problem out clearly to me (ie I interpreted "but not required" as a general statement, not as something that referred to a missing "require" clause!) So, here's another suggestion that I believe would make this clearer.
You might dislike this too, but I tried at least! :) |
If there's a way to rephrase the error message to make it more clear what's wrong, I think that's reasonable. However, we want to keep it concise, and recommend a single command to fix the problem without other side effects. Something like this might get the point across, but it still seems pretty verbose to me.
|
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What did you do?
We have a fairly large repo (go-ethereum), which is a standalone application, but it can also be consumed as a library. We also have a code generator in our command suite which takes some API definitions and generates Go wrappers for them. The generated code relies on our main repository as a library.
The above is nothing special, but we'd like to have a test suite that uses the generator to wrap some APIs an then run them to make sure the generated code is executable and does what we expect. Currently the test uses the generator to create the wrapper Go files and then attempts to build it. Since the build depends on the main repo, we need to tell
go
(orgo mod
) about it.Previously we used
go mod init ...
and thengo mod edit --replace https://github.com/ethereum/go-ethereum=path/to/checkout
to have the tester use the current working code (needed both for local development as well as PRs; that they always test the checked out code, not a pinned upstream version). Up until Go 1.15 this worked fine. Starting from Go 1.16, this setup is rejected.What did you expect to see?
Go mod in 1.16 refuses to accept a replacement directive if the package being replaced isn't already part of the mod file. I could add a call to
go get github.com/ethereum/go-ethereum
orgo mod edit --require github.com/ethereum/go-ethereum@master
to the build, but that would do a network request and download out repo of >500MB. It makes no sense to have a test download external code when it's not even needed at all (the needed code is the checked out working copy the test runs from).I guess my question is how can I convince Go mod to add a
replace
directive to a local copy without having it download an upstream copy first, which just gets discarded anyway.What did you see instead?
The text was updated successfully, but these errors were encountered: