gogo / protobuf

[Deprecated] Protocol Buffers for Go with Gadgets
Other
5.65k stars 810 forks source link

example.proto:33:1: Import "github.com/gogo/protobuf/gogoproto/gogo.proto" was not found or had errors. #674

Open theoneLee opened 4 years ago

theoneLee commented 4 years ago
edzdeMacBook-Pro:example edz$ make
(protoc -I=. -I=/Users/edz/go/src/github.com/gogo/protobuf/protobuf -I=/Users/edz/go/src --gogo_out=. example.proto)
/Users/edz/go/src/github.com/gogo/protobuf/protobuf: warning: directory does not exist.
github.com/gogo/protobuf/gogoproto/gogo.proto: File not found.
example.proto:33:1: Import "github.com/gogo/protobuf/gogoproto/gogo.proto" was not found or had errors.
make: *** [regenerate] Error 1
edzdeMacBook-Pro:example edz$ pwd
/Users/edz/go/pkg/mod/github.com/gogo/protobuf@v1.3.1/test/example

I run the demo and got an error.

https://github.com/gogo/protobuf/blob/master/test/example/example.proto

theoneLee commented 4 years ago

And I had already run those install script.

go get github.com/gogo/protobuf/protoc-gen-gofast
go get github.com/gogo/protobuf/proto
go get github.com/gogo/protobuf/jsonpb
go get github.com/gogo/protobuf/protoc-gen-gogo
go get github.com/gogo/protobuf/gogoproto

And my $GOPATH/bin had some exec programs.

edzdeMacBook-Pro:bin edz$ pwd
/Users/edz/go/bin
edzdeMacBook-Pro:bin edz$ ls
fillstruct      gocode-gomod        gopkgs          gotests         micro           protoc-gen-gogo
go-outline      godef           gopls           guru            mockgen         protoc-gen-micro
go-symbols      goimports       gorename        hello_world     protoc-gen-go       xgen
gocode          golint          goreturns       impl            protoc-gen-gofast

But my $GOPATH/src doesn't have gogo dir. Is it the error reason?

edzdeMacBook-Pro:github.com edz$ go env
GO111MODULE="on" 
GOPROXY="https://goproxy.cn,https://goproxy.io,direct"
kamly commented 3 years ago

i also meet this problem , how to solve it ?

Tsovak commented 3 years ago

hey @theoneLee, try to replace protoc -I=. ... to protoc -I=. -I$(GOPATH)/src ... in the makefile

PacoDw commented 2 years ago

Could you be able to resolve it?

smallyunet commented 2 years ago

I occur the same problem because I turn on GO111MODULE. I solved this problem after executing those commands:

export GO111MODULE="off"
go get github.com/gogo/protobuf

Then make could success:

smallyu@bogon example % make
(protoc -I=. -I=/Users/smallyu/go/src/github.com/gogo/protobuf/protobuf -I=/Users/smallyu/go/src --gogo_out=. example.proto)
smallyu@bogon example %

And when I want to generator another .proto file, I use the command (after turn off GO111MODULE and already get github.com/gogo/protobuf):

 protoc -I=. -I=$GOPATH/src/github.com/gogo/protobuf/protobuf -I=$GOPATH/src --gogo_out=. another.proto 
cywang1905 commented 2 years ago

I occur the same problem because I turn on GO111MODULE. I solved this problem after executing those commands:

export GO111MODULE="off"
go get github.com/gogo/protobuf

Then make could success:

smallyu@bogon example % make
(protoc -I=. -I=/Users/smallyu/go/src/github.com/gogo/protobuf/protobuf -I=/Users/smallyu/go/src --gogo_out=. example.proto)
smallyu@bogon example %

And when I want to generator another .proto file, I use the command (after turn off GO111MODULE and already get github.com/gogo/protobuf):

 protoc -I=. -I=$GOPATH/src/github.com/gogo/protobuf/protobuf -I=$GOPATH/src --gogo_out=. another.proto 

Agree with you. After turn off GO111MODULE, the problem is solved. My example is like:

proto file:

syntax = "proto3";
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
import "google/protobuf/duration.proto";

Command line:

$ protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/gogo/protobuf/protobuf --gogo_opt=paths=source_relative --gogo_opt=Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types --gogo_out=. config.proto
bohehe commented 2 years ago

I resolved this by specifying the proto_path

protoc --go_out=. --go_opt=paths=source_relative \
    --go-grpc_out=. --go-grpc_opt=paths=source_relative \
    path/to/your/target/protofile --proto_path=$GOPATH/src/ --proto_path=.

--proto_path should be specified to the directory in which to search for imports

-> % protoc --help
Usage: protoc [OPTION] PROTO_FILES
Parse PROTO_FILES and generate output based on the options given:
  -IPATH, --proto_path=PATH   Specify the directory in which to search for
                              imports.  May be specified multiple times;
                              directories will be searched in order.  If not
                              given, the current working directory is used.
                              If not found in any of the these directories,
                              the --descriptor_set_in descriptors will be
                              checked for required proto file.
sayhi-yuan commented 1 year ago

i can't