-
Notifications
You must be signed in to change notification settings - Fork 18k
interesting module build issue when trying examples quickly #43829
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
Comments
If you use go1.16+ (you can try the beta now), the » go build .
go: cannot find main module, but found .git/config in /home/user/testrepo-232
to create a module there, run:
go mod init and yes, in seeing as this is not going to be an issue in the next release, I'm going to close this, please comment/reopen if you disagree |
@seankhliao Thanks for that info. Does this mean that the library I'm using should therefore be dependent on version go 1.16? Hence, does this also mean that ALL module-dependant libraries should probably bump up their go-lang version specs in their go.mod files to 1.16? (Looks like 1.16 is the first go version that will fully work with modules correctly?) .. I think this might be some important guidance for creating modules from now on... (or does it not make a difference anyway as it's not using module mode)? |
What matters is if you the end user are in module mode. If you're not, then go doesn't care about versions no matter what the libraries say they want. If you are then it will try to respect the requested versions. go1.16 (the tool version) makes module mode the default, you can get the same behavior now if you set |
Hi, Can we re-open this (sorry, I'm not sure how to do that)? With go1.16 (released version), I get the following problem (if I delete the go.mod and go.sum files). Apparently, "go get" is no longer sufficient to pull in a module! Is this expected behavior (seems odd to me)?
The only thing I can see in the docs is this: "go get example.com/mod@patch now requires that some version of example.com/mod already be required by the main module. (However, go get -u=patch continues to patch even newly-added dependencies.) " .. but that sounds like it's only for explicit module/patch levels rather than for any go get? Also the docs explicitly state: .. I'm confused (again)! :) |
You always need go.mod |
..if that's the case, the docs need revising to make that clear!! |
Note: 1.16 seems to have broken this approach! ref: #44529 |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
don't know.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I tried to build and run a simple example program for "go-prompt" as a standalone file in a new, empty directory.
ref:
c-bata/go-prompt#215
(I often do this to quickly test out a new package: copy an example and just try to run it to see if it simply works. In this case it didn't, and I would normally simply ignore the package and assume that it was unmaintained/immature/poorly tested. Luckily, in this case I persevered and discovered quite an interesting thing regarding how an apparently good looking module dependency can fail without obvious reason.)
What did you expect to see?
It should have built (with a specified older 1.1.0 module version, which had an older, different function signature), but failed (due to an API change)
What did you see instead?
A confusing build failure (it tried to build against code that was not in the specified module version!).
Conclusion
Note that I think this was resolved by forcing "module-mode" for the build ("to be confirmed" though..)
I'm raising this bug because this is a very simple error to make (ie not create a go.mod file simply to run a one-file sample test), and more significantly, a very odd, tricky, confusing thing to analyze/debug/fix: I almost gave up, but luckily, on this occasion, it piqued my interest.
Maybe there should/could be some kind of warning when the non-module mode is using a latest version of a module rather than the specified modules in an imported package?
I realize that this is a temporary annoyance (ie until the world moves over to modules, but please can you confirm how this would work in the New World, ie do you always have to do a go mod init simply to run a one-file test? This is an uncomfortable user-experience and a new barrier to entry...)
P.S. Can you confirm that my guess is right (ie that non-module mode would pull in the latest version of a module and hence ignore the careful dependency management that someone has tried to set up?) Also, I couldn't find this documented anywhere (luckily I remembered reading something about it a while ago).
The text was updated successfully, but these errors were encountered: