-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: 'fmt x.go' fails with cannot find main module
#27099
Comments
Sorry but formatting does rely on compilation. In general 'go fmt pkg' must figure out what files are in the package. We could add a special case for fmt not to chase down deps and then a different special case for 'go fmt x.go' not to require module initialization, and maybe we should, but this problem is not really new in modules. In any event, I think you are really looking for gofmt -w. |
Hi @rsc, Thanks for the answer.
This sounds like a good solution to me. Since a client uses a path to file, there is no need to resolve
I'm not sure what you mean by this, could you elaborate, please? The modules are new themselves, as well as
As far as I remember we migrated to |
He means this was always the case. And not something due to modules. |
Still not clear. Requiring module initialization is not because of modules? But there is no module without modules, and |
Not the module initialization part, the requirement of compilation part (like syntax errors and such). Now with modules, gofmt requires module initialization. Hope that is clear (And what was intended by Russ). |
Thanks, still I'm pretty sure it was related to a module initialization part and would like to know the details. As I understood from the initial answer, the compilation is required for resolving package and files in it, not for syntax checking. Building AST for formatting (and syntax checking as part of it) is not a compilation, it's a parsing a particular file isolated from other files in a package (and from module's dependencies), and it doesn't lead to the problem described here.
As Russ pointed out This is the point of the issue, I don't see any reason to require module initialization for formatting a file, not a package. And I think this is a new thing since modules are new. |
My apologies, I did not see it was |
Would fixing #27166 help you? |
@josharian I think it will. Thanks! |
It is OK to change |
cannot find main module
cannot find main module
Change https://golang.org/cl/153459 mentions this issue: |
What version of Go are you using (
go version
)?go1.11rc1 windows/amd64
What operating system and processor architecture are you using (
go env
)?Windows, Linux
What did you do?
C:\gopath\src\testProject\main.go
with a contentpackage main; func main() {}
on linux:
What did you expect to see?
Formatted main.go, since formatting does not rely on a compilation, an absence of main module doesn't seem like a good reason to stop formatting.
What did you see instead?
The text was updated successfully, but these errors were encountered: