Skip to content

Build errors when Go modules are enabled #328

@dfawley

Description

@dfawley

In grpc/grpc-go#2281, I converted grpc-go to support the new modules in Go. However, without a workaround, staticcheck gave the following error:

$ staticcheck -ignore '
> internal/transport/transport_test.go:SA2002
> benchmark/benchmain/main.go:SA1019
> stats/stats_test.go:SA1019
> test/end2end_test.go:SA1019
> balancer_test.go:SA1019
> balancer.go:SA1019
> clientconn_test.go:SA1019
> internal/transport/handler_server_test.go:SA1019
> internal/transport/handler_server.go:SA1019
> ' ./...
.../go/pkg/mod/github.com/golang/mock@v1.1.1/gomock/controller.go:60:2: could not import golang.org/x/net/context (cannot find package "golang.org/x/net/context" in any of:
	.../go111/go/src/golang.org/x/net/context (from $GOROOT)
	.../go/src/golang.org/x/net/context (from $GOPATH))
couldn't load packages due to errors: google.golang.org/genproto/googleapis/rpc/status, github.com/golang/protobuf/ptypes/any, ./channelz/service and 21 more

The workaround: make a symlink in $GOPATH/src for every package needed from $GOPATH/pkg/mod (see vet.sh immediately before running staticcheck).

I found this related issue: golang/go#26504. However, it was resolved before the 1.11 release and was marked as a release blocker, so my best guess is it was incorporated in the release. The advice in that issue is to switch to golang.org/x/tools/go/packages from go/build. Maybe that will fix all related issues?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions