techschool/pcbook-go

protoc-gen-go failed :: The import path must contain at least one forward slash ('/') character."

Opened this issue Β· 23 comments

protoc --version
libprotoc 3.15.6
make gen

protoc --proto_path=proto proto/*.proto --go_out=plugins=grpc:pb --grpc-gateway_out=:pb --openapiv2_out=:swagger
protoc-gen-go: invalid Go import path "." for "auth_service.proto"

The import path must contain at least one forward slash ('/') character.

See https://developers.google.com/protocol-buffers/docs/reference/go-generated#package for more information.

--go_out: protoc-gen-go: Plugin failed with status code 1.
make: *** [Makefile:2: gen] Error 1

I assume they made some changes for the newest protoc that now require you to set a import path with at least one "/" ?!

same issue!

same issue

same issue

➜  rpcEcomm protoc --version                                  
libprotoc 3.6.1

I solved it, you need to fix the go_package inside the proto file

Initially, my .proto file was

syntax = "proto3";

package greet;
option go_package="greetpb";

service GreetService{}

I changed the value of go_package from "greetpb" to "./greet/greetpb" and it started working.

You need to change your option go_package into
option go_package = "./;pb";
The first param means relative path where the code you want to generate. The path relative to the --go_out , you set in your command.

you need set the path twice ,it is confused, I know....

The second is just the package name.

You need to change your option go_package into
option go_package = "./;pb";
The first param means relative path where the code you want to generate. The path relative to the --go_out , you set in your command.

you need set the path twice ,it is confused, I know....

The second is just the package name.

Saved my day!

You need to change your option go_package into
option go_package = "./;pb";
The first param means relative path where the code you want to generate. The path relative to the --go_out , you set in your command.
you need set the path twice ,it is confused, I know....
The second is just the package name.

Saved my day!

Save two days ~!!!

You need to change your option go_package into
option go_package = "./;pb";
The first param means relative path where the code you want to generate. The path relative to the --go_out , you set in your command.

you need set the path twice ,it is confused, I know....

The second is just the package name.

That works,thank you

thanks

i dont even put my proto file inside some folder, is it has anything to do with folder if i user go_package =".folder/;pb"??

You need to change your option go_package into
option go_package = "./;pb";
The first param means relative path where the code you want to generate. The path relative to the --go_out , you set in your command.

you need set the path twice ,it is confused, I know....

The second is just the package name.

Thank you very much! Saved my day :)

Initially, my .proto file was

syntax = "proto3";

package greet;
option go_package="greetpb";

service GreetService{}

I changed the value of go_package from "greetpb" to "./greet/greetpb" and it started working.

Awesome details there! Save me 1 day! Thank you!

protoc --proto_path=proto proto/*.proto --go_out=plugins=grpc:pb

good

Thank you guys, you help me a lot.

Thank you !!

I hacked proto-gen-go to fix this, and it works just fine:

I fixed it changing the go_package value from protofiles;pb to ./protofiles;pb

option go_package = "./protofiles;pb";

You need to change your option go_package into option go_package = "./;pb"; The first param means relative path where the code you want to generate. The path relative to the --go_out , you set in your command.

you need set the path twice ,it is confused, I know....

The second is just the package name.

Thanks a lot, really saved me there!
I changed my go_package to
option go_package = "./;proto";

and this was the command I used (the folder name I used to store my proto file is proto)
protoc --proto_path=proto --go_out=proto --go_opt=paths=source_relative proto.proto

... it's way easier to just use a modified version of protoc-gen-go without the unnecessary check for a / in the package import path.

it works just fine without it.

see:

Hey guys, I recently made a video in my Backend Master Class course with the latest version of protoc, so this is no longer an issue.
You can check it out here: [Backend #40] Define gRPC API and generate Go code with protobuf

Discuss with me & other students on Tech School Discord group

incase any one wants the generated file to be in same folder with .proto just use option go_package="../greetpb";

ε½“ε‰θ·―εΎ„ιƒ½ε˜δΈΊδΊ†./
ε¦‚ζžœθ¦ζƒ³ζŠŠζ–‡δ»Άη”Ÿζˆεˆ°ε½“ε‰θ·―εΎ„δΈ‹οΌŒη”Ÿζˆε‘½δ»€ηš„.εΊ”θ―₯写为./
ζ—§η‰ˆ
protoc --go_out =. --go-grpc_out =. demo.proto
ζ–°η‰ˆ
protoc --go_out=./ --go-grpc_out=./ demo.proto