Skip to content
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: can't load package: package main: cannot find package "main" in any of: /usr/local/go/src/main (from $GOROOT) /Users/josuezafra/go/src/main (from $GOPATH) #35000

Closed
JZafrag opened this issue Oct 19, 2019 · 9 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@JZafrag
Copy link

JZafrag commented Oct 19, 2019

So I just got this error in the cmd when I tried to run a simple program:

package main

import (
"net/http"
)

func main() {
http.listenAndServe(":3000", nil)
}

And the error I got while trying to run go build main.go:

$ go build main.go can't load package: package main: cannot find package main in any of:

/usr/local/go/src/main (from $GOROOT)
/Users/josuezafra/go/src/main (from $GOPATH)

I'm sorry if this is not an error from Go but from myself, I literally started learning Go today

@ianlancetaylor
Copy link
Contributor

Did you type exactly go build main.go? It looks like you typed go build main.

@ianlancetaylor ianlancetaylor added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Oct 19, 2019
@dylan844r
Copy link

I'm having a similar problem. I keep getting can't load package: package .: no Go files in C:\Users\***** every time I try to use the go build command

@ianlancetaylor
Copy link
Contributor

@dylan844r What precisely do you do?

@dylan844r
Copy link

@ianlancetaylor C:\Users\shumb>go build C:\Users\shumb>go build can't load package: package .: no Go files in C:\Users\shumb I was trying to use this after successfully using the go get tool. I've been stuck here for a while and haven't found any answers on google

@ianlancetaylor
Copy link
Contributor

@dylan844r The formatting is a bit wonky but it looks like you ran a simple go build. When you run go build with no arguments, it will build the package in your current directory. In you case it is telling you that there is no package in your current directory.

If you ran go get github.com/x/y, then you can build that by running go build github.com/x/y.

This is not the same problem as the original issue here, which does not say no Go files but instead says cannot find package main. Let's take discussion of this side issue elsewhere, preferably a forum; see https://golang.org/wiki/Questions. Thanks.

@JZafrag
Copy link
Author

JZafrag commented Oct 21, 2019

@ianlancetaylor Yes I did type it correctly. Sorry for not answering earlier, I was very busy with oher things

I actually did type go build main.go, I just don't know why that happens.

@ianlancetaylor
Copy link
Contributor

I can recreate the problem exactly if I type

go build main

I cannot recreate it if I type

go build main.go

I don't know why you are seeing what you are seeing.

@bcmills
Copy link
Contributor

bcmills commented Oct 21, 2019

@JZafrag, please fill out the complete issue template. (You can get a fresh copy from https://golang.org/issue/new.)

In order to diagnose the problem, we need to know the Go version in use, the output of go env, and the directory layout of your source code (especially in relation to GOPATH, GOROOT, and any go.mod file that may be present).

@bcmills bcmills added WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. and removed WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Oct 21, 2019
@gopherbot
Copy link

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.)

@golang golang locked and limited conversation to collaborators Nov 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

5 participants