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: no helpful error message for "no Go files" with modules #27122

Open
FiloSottile opened this Issue Aug 21, 2018 · 4 comments

Comments

Projects
None yet
6 participants
@FiloSottile
Copy link
Member

FiloSottile commented Aug 21, 2018

Without modules, the go tool informs me that I'm trying to build a package with no Go files:

$ go1.11rc1 build ./vcs-test
can't load package: package golang.org/x/build/vcs-test: no Go files in /Users/filippo/src/golang.org/x/build/vcs-test

With modules, I get an obscure error:

$ GO111MODULE=on go1.11rc1 build ./vcs-test
go: finding golang.org/x/build/vcs-test latest
can't load package: package golang.org/x/build/vcs-test: unknown import path "golang.org/x/build/vcs-test": cannot find module providing package golang.org/x/build/vcs-test
@thepudds

This comment has been minimized.

Copy link

thepudds commented Dec 28, 2018

Note that this relatively unhelpful error message still occurs with 1.11.4 and 1.12beta1.

# Failing example. There are no .go files (and hence no package) in the same directory 
# as the main `go.mod` file.

mkdir -p /tmp/scratchpad/bitbucket-module-bad
cd /tmp/scratchpad/bitbucket-module-bad
go mod init bitbucket.org/foo/bar

mkdir baz
cat <<EOF > baz/baz.go
package baz

func Hello() string { return "Hello from bitbucket.org/foo/bar/baz" }
EOF

cd /tmp/scratchpad/bitbucket-module-bad
go build -v 

Fails with:

$ go build -v
Fetching https://bitbucket.org?go-get=1
Parsing meta tags from https://bitbucket.org?go-get=1 (status code 200)
can't load package: package bitbucket.org/foo/bar: unknown import path "bitbucket.org/foo/bar": 
cannot find module providing package bitbucket.org/foo/bar

One solution (as covered in an FAQ on the modules wiki) is go build ./... or other variations.

CC @myitcv @bcmills @heschik

@hyangah

This comment has been minimized.

Copy link
Contributor

hyangah commented Dec 28, 2018

#29268 is related.

@crhntr

This comment has been minimized.

Copy link

crhntr commented Dec 30, 2018

I have been writing Go (it was the first language I really learned well) and so ./... seemed normal to me, but I was recently helping a very experienced C# engineer on board onto my team. We were pair-programming and we came across this issue and I used go install ./... and he was a little weirded out but thought it was easy to remember but was unintuitive.

@bcmills bcmills added this to the Go1.13 milestone Jan 14, 2019

@lpar

This comment has been minimized.

Copy link

lpar commented Jan 28, 2019

Perhaps ./... could be the default if GO111MODULE=on or there's a go.mod file in the current directory?

Failing that, the error message could use some work. can't load package: package projectname: unknown import path "projectname": cannot find module providing package projectname doesn't suggest to me "You forgot to specify which module to compile, maybe with ./...".

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