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

Closed
FiloSottile opened this issue Aug 21, 2018 · 8 comments
Closed

cmd/go: no helpful error message for "no Go files" with modules #27122

FiloSottile opened this issue Aug 21, 2018 · 8 comments
Labels
FrozenDueToAge modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@FiloSottile
Copy link
Contributor

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
@FiloSottile FiloSottile added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. modules labels Aug 21, 2018
@thepudds
Copy link
Contributor

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
Copy link
Contributor

hyangah commented Dec 28, 2018

#29268 is related.

@crhntr
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
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 ./...".

@thepudds
Copy link
Contributor

thepudds commented Apr 8, 2019

#31270 might be a dup of this.

@shaneHowearth
Copy link

shaneHowearth commented May 31, 2019

I was following a tutorial for something (gRPC) and the tutorial makes use of modules, so I got to learn about them too \o/

However I had an issue where I had made a mistake and the error message from go build was not very helpful.

Below is pasted the file tree, the root go.mod, the code that was generating the error, the command being executed and the error message. The error turned out to be that the import path was pointed at a directory with no go source files, but the error reported was "cannot find module providing package"

.
.
├── go.mod
├── go.sum
└── part_1
    ├── api
    │   └── proto
    │       └── v1
    │           └── todo-service.proto
    ├── cmd
    │   ├── client-grpc
    │   │   ├── client-grpc
    │   │   └── main.go
    │   └── server
    │       └── main.go
    ├── create_todo_table.sql
    ├── go.sum
    ├── pkg
    │   ├── api
    │   │   └── v1
    │   │       └── todo-service.pb.go
    │   ├── cmd
    │   │   └── server
    │   │       └── server.go
    │   ├── protocol
    │   │   └── grpc
    │   │       └── server.go
    │   └── service
    │       └── v1
    │           ├── todo-service.go
    │           └── todo-service_test.go
    └── third_party
        └── google
            └── protobuf
                ├── any.proto
                ├── api.proto
                ├── compiler
                │   └── plugin.proto
                ├── descriptor.proto
                ├── duration.proto
                ├── empty.proto
                ├── field_mask.proto
                ├── source_context.proto
                ├── struct.proto
                ├── timestamp.proto
                ├── type.proto
                └── wrappers.proto

20 directories, 25 files
=======================================
~/go/src/shane/go.mod
module shane

require (
	github.com/DATA-DOG/go-sqlmock v1.3.3
	github.com/go-sql-driver/mysql v1.4.1
	github.com/golang/protobuf v1.3.1
	google.golang.org/grpc v1.21.0
)
========================================
~/go/src/shane/part_1/cmd/server
package main

import (
	"fmt"
	"os"

	"shane/part_1/pkg/cmd"
)

func main() {
	if err := cmd.RunServer(); err != nil {
		fmt.Fprintf(os.Stderr, "%v\n", err)
		os.Exit(1)
	}
}
========================================
go build . # inside ~/go/src/shane/part_1/cmd/server
main.go:7:2: unknown import path "shane/part_1/pkg/cmd": cannot find module providing package shane/part_1/pkg/cmd

@andybons andybons modified the milestones: Go1.13, Go1.14 Jul 8, 2019
@gopherbot
Copy link
Contributor

Change https://golang.org/cl/185345 mentions this issue: cmd/go: rationalize errors in internal/load and internal/modload

@rsc rsc modified the milestones: Go1.14, Backlog Oct 9, 2019
@bcmills
Copy link
Contributor

bcmills commented Dec 6, 2019

This appears to be fixed at head.

~/src/golang.org/x/build$ gotip version
go version devel +0915a19a Fri Dec 6 05:12:15 2019 +0000 linux/amd64

~/src/golang.org/x/build$ GO111MODULE=on gotip build ./vcs-test
can't load package: package ./vcs-test: no Go files in /usr/local/google/home/bcmills/src/golang.org/x/build/vcs-test

~/src/golang.org/x/build$ GO111MODULE=off gotip build ./vcs-test
can't load package: package golang.org/x/build/vcs-test: no Go files in /usr/local/google/home/bcmills/src/golang.org/x/build/vcs-test

@bcmills bcmills closed this as completed Dec 6, 2019
gopherbot pushed a commit that referenced this issue Feb 28, 2020
This change is a non-minimal fix for #32917, but incidentally fixes
several other bugs and makes the error messages much more ergonomic.

Updates #32917
Updates #27122
Updates #28459
Updates #29280
Updates #30590
Updates #37214
Updates #36173
Updates #36587
Fixes #36008
Fixes #30992

Change-Id: Iedb26d2e0963697c130df5d0f72e7f83ec2dcf06
Reviewed-on: https://go-review.googlesource.com/c/go/+/185345
Reviewed-by: Michael Matloob <[email protected]>
Reviewed-by: Jay Conrod <[email protected]>
@golang golang locked and limited conversation to collaborators Dec 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

10 participants