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

Open
JZafrag opened this issue Oct 19, 2019 · 8 comments

Comments

@JZafrag
Copy link

@JZafrag 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

This comment has been minimized.

Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Oct 19, 2019

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

@dylan844r

This comment has been minimized.

Copy link

@dylan844r dylan844r commented Oct 20, 2019

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

This comment has been minimized.

Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Oct 20, 2019

@dylan844r What precisely do you do?

@dylan844r

This comment has been minimized.

Copy link

@dylan844r dylan844r commented Oct 20, 2019

@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

This comment has been minimized.

Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Oct 20, 2019

@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

This comment has been minimized.

Copy link
Author

@JZafrag 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

This comment has been minimized.

Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Oct 21, 2019

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

This comment has been minimized.

Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.