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: allow go run .
in module mode without a go.mod file
#36513
Comments
Why are you setting In any case, it seems like you disagree with #32027. That discussion happened a while ago, though. |
Some people might have set it on globally before for some other reasons. |
The current design also causes inconveniences in writing some Go tutorials with a simple Go file (and might have caused for some old tutorials). They must remind readers to create a If some new gophers have set |
I think it depends on what exactly the user is doing. If they need third party dependencies, requiring a If they don't need third party dependencies, i.e. they use the standard library alone, I agree that a But it would still be a good idea to use a |
Yes, the At least, the error message should not depend on whether or not there is a |
I'd recommend against setting This specific change in behavior was #32027. In short, if a user has
Import paths in modules other than
The rationale for this change was that early on, people would set I don't think this necessarily means @bcmills @matloob WDYT? We might want to do this if/when |
At the very least, we would need to decide what language version to use in module mode for a package in a directory outside of any module. We would also need to determine the effective import path for such a package for debug info and build caching. (Perhaps the same import path that we generate in |
It looks this problem has been fixed in go1.16beta1. |
A new problem if
The embedding feature is not usable without a |
Just want to say I came back to a go project that I (thankfully) rarely need to touch more than once per year, and found it really confusing to get back into it and just build something.
No matter what I had set for I second the OP, this isn't really user-friendly for simple projects. |
@derrickb it looks running simple go files doesn't need a |
@go101 |
Yes. Sorry, I forgot that. |
@go101 I need to mess around with it more... my project is just three small .go files and using |
@derrickb |
|
Yes, on windows you'd have to list the files individually: |
There's been some renewed attention on this issue, since In module-aware mode, if there is no This last restriction was added in Go 1.14 (#24031). Since there's no go.mod file, there's no place for the go command to save which version of each dependency is used, so before that, it went out to the network to look up every missing import. This was slow and non-deterministic, and we didn't feel that it was a good experience for beginners. An alternative would be using modules already downloaded into the module cache, but there's potential to use unexpectedly old versions, so we decided against that. For this issue, it seems reasonable to me to let Does that sound reasonable? |
Yes, please. The distinction between a list of .go files and a path, with respect to the no-go.mod mode, is surprising to me; I learned about it from your message. |
Hi @jayconrod I agree this would be a nice and friendly improvement.
One clarifying question: would this also apply to commands like |
@thepudds Yes, |
go run .
in module mode without a go.mod file
This comment has been minimized.
This comment has been minimized.
Well this has caused my first experience of Go to be awful. I just checked out a project (https://github.com/rancher/migration-tools) and hoped to run it but I have no clue how. I figured that I needed to run |
Yeah this made go a little less "pick up and go" which is such a shame, as that was a great feature of the language and tools. |
@mjaggard, what were the commands that you ran and what was the output produced by those commands? Even today, |
|
Vote for such "pick up and go" feature, which makes Take the below code for an example:
For go1.13, when I run For go1.14.1, it fails without
And for go1.17.3, it also fails without
|
Yes! It is pretty annoying when you want to test out some code snippets and all you can do is to setup a small project for this. I think it is good to support this kind of script-style exection. |
Need to Go back to its root. Keep Go simple please! |
is there any good suggestions for this problem? |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What did you do?
main.go
file.GO111MODULE=on
go run .
in the project folder.What did you expect to see?
Run okay.
What did you see instead?
or for a git repository
The text was updated successfully, but these errors were encountered: