pcbook-go icon indicating copy to clipboard operation
pcbook-go copied to clipboard

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

Open ghost opened this issue 4 years ago • 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 "/" ?!

ghost avatar Mar 23 '21 16:03 ghost

same issue!

yifanes avatar Apr 01 '21 09:04 yifanes

same issue

niolap avatar Apr 08 '21 11:04 niolap

same issue

➜  rpcEcomm protoc --version                                  
libprotoc 3.6.1

ghost avatar Apr 09 '21 19:04 ghost

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

ghost avatar Apr 09 '21 20:04 ghost

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.

antblood avatar Apr 17 '21 17:04 antblood

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.

Jiaget avatar Apr 20 '21 11:04 Jiaget

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!

jesseXu avatar Apr 21 '21 13:04 jesseXu

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

DachuanZhao avatar Apr 23 '21 11:04 DachuanZhao

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

liuzhiqiang123gitHub avatar May 12 '21 13:05 liuzhiqiang123gitHub

thanks

amtoor avatar May 21 '21 07:05 amtoor

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

rjandonirahmana avatar Jul 13 '21 05:07 rjandonirahmana

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

gain620 avatar Aug 28 '21 20:08 gain620

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!

jeffer-tan avatar Dec 18 '21 23:12 jeffer-tan

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

good

loloxwg avatar Jan 25 '22 06:01 loloxwg

Thank you guys, you help me a lot.

mencosk avatar Feb 20 '22 07:02 mencosk

Thank you !!

arijus303 avatar Mar 28 '22 19:03 arijus303

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

  • https://github.com/paralin/protobuf-go/commit/badd5ddf78097f5449793dfd620828df2d77a840
  • https://github.com/paralin/protobuf-go/commit/a915b3bc160926e5c42e6ebd996d3b1719de2f38

paralin avatar Mar 28 '22 22:03 paralin

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

option go_package = "./protofiles;pb";

luizcalazans16 avatar Apr 06 '22 00:04 luizcalazans16

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

y0naa avatar Jun 09 '22 02:06 y0naa

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

  • https://github.com/aperturerobotics/protobuf-go/commit/349b2ae33224119ac0edc3ff180d0d21da89ac0c
  • https://github.com/aperturerobotics/protobuf-go/commit/78b627edc1c2f87ee69208f3d067cd592936e299
  • https://github.com/aperturerobotics/protobuf-go/commit/dcfbe19b6cd6ac17078f7bd3719bf7ff1a1c5f06

paralin avatar Jun 09 '22 03:06 paralin

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

techschool avatar Jun 09 '22 16:06 techschool

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

Baksman avatar Jul 14 '22 09:07 Baksman