techschool / pcbook-go

474 stars 143 forks source link

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

Open ghost opened 3 years ago

ghost commented 3 years ago
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 "/" ?!

yifanes commented 3 years ago

same issue!

niolap commented 3 years ago

same issue

ghost commented 3 years ago

same issue

➜  rpcEcomm protoc --version                                  
libprotoc 3.6.1
ghost commented 3 years ago

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

antblood commented 3 years ago

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.

Jiaget commented 3 years ago

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.

jesseXu commented 3 years ago

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!

DachuanZhao commented 3 years ago

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 ~!!!

liuzhiqiang123gitHub commented 3 years ago

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

amtoor commented 3 years ago

thanks

rjandonirahmana commented 3 years ago

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"??

gain620 commented 3 years ago

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 :)

jeffer-tan commented 2 years ago

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!

loloxwg commented 2 years ago

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

good

mencosk commented 2 years ago

Thank you guys, you help me a lot.

arijus303 commented 2 years ago

Thank you !!

paralin commented 2 years ago

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

luizcalazans16 commented 2 years ago

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

option go_package = "./protofiles;pb";

jwnalynsh commented 2 years ago

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

paralin commented 2 years ago

... 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:

techschool commented 2 years ago

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

Baksman commented 2 years ago

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

sparklyi commented 3 months ago

当前路径都变为了./ 如果要想把文件生成到当前路径下,生成命令的.应该写为./ 旧版 protoc --go_out =. --go-grpc_out =. demo.proto 新版 protoc --go_out=./ --go-grpc_out=./ demo.proto