-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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. |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as duplicate.
This comment was marked as duplicate.
It's no surprise that @mjaggard's first experience with Go was bad. I would be impressed if he stuck around. And if you look up Imagine a poor beginner programmer (or at least Go newbie) in this situation and how suddenly they are out of their depth. All they wanted to do was try an interesting piece of code they found online and now Go is asking them to choose a name for their module to share with others. Or in my case, an experienced Go programmer 5 minutes ago. And now I'm sitting here asking "why do I need to choose a throwaway name to initialize a module just so I can (not to mention the cognitive overhead of having to page back in all the go module arcana such as The solution is simple: |
I hate to be that guy.. making the module requirement a default and thus forcing the duplication of packages all over my hard drive wasn't the best of ideas :-( I made the mistake of updating Go on a server where the code was assembled in a folder during deployment. |
@jayconrod It should be possible to find a compromise between "fast and deterministic" and "easy to run snippets and use go as a scripting language". For example, we can imagine that if the What "not so old" means and whether "on the fly" packages should be cached could be configurable, with good reasonable defaults for newbies. There could also be a flag like |
@kpym I very much appreciate this line of thinking. In my eyes, the mandate of reproducible builds and of deterministic dependency management goes against the idea of "simplicity". Those are important for organizational software deployment - not so much for almost every other use case. Having come to terms with the situation, a command line option for controlling would be simple enough addition (imo). Building on your idea, your issue is better addressed with another option for
That would not directly solve the issue with |
Just stumbled upon this today. I want to have a number of local Golang playground scripts and the inability to just
...and I agree that should be the default behavior. But I would appreciate a Having a no-fuss Failing all that, I suppose I can make my own Golang workspace with subdirs for all my playground scripts and use something like (I also tried |
// |
Go team, please prioritize this! As a brand new Go user I ended up here after trying to run a few simple script-like pieces of code I found online. A new user just trying to build and run a few simple examples should not have to Google inscrutable error messages and read through a GitHub issue to try to figure out how to get it working. The beginner experience should not be this painful! Why is this issue languishing in the Unplanned/Backlog milestones? Please prioritize it, for the sake of new users and for making Go more of a joy to use, especially in the "pick up and go" type of use case. |
@ErikSwan I appreciate the enthusiasm, but there are over eight thousand open issues right now, and a limited number of hands. If they were to listen to the requests to prioritize some issues over others, we'd make even less progress on the overall number of issues. If you really care about an issue in particular which is currently in the backlog, the best way to help is to contribute :) |
This should be possible, |
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: