protoc "--go_out: protoc-gen-go: Plugin failed with status code 1" in CI
protoc launched protoc-gen-go successfully but the plugin itself exited with status 1. The plugin prints its own error above this line: most often a missing go_package option or an unresolved import mapping.
What this error means
protoc fails with "--go_out: protoc-gen-go: Plugin failed with status code 1", preceded by a plugin message about go_package or an M option for an imported file.
protoc-gen-go: unable to determine Go import path for "api/v1/user.proto"
Please specify either:
- a "go_package" option in the .proto source file, or
- a "M" argument on the command line.
--go_out: protoc-gen-go: Plugin failed with status code 1.Common causes
The .proto file has no go_package option
protoc-gen-go needs a Go import path to place generated files; without option go_package = "..." it cannot determine one and exits 1.
An imported .proto lacks an M mapping
A referenced file has no go_package and no M<file>=<import> argument on the command line, so the plugin cannot resolve where its types live.
How to fix it
Add a go_package option to every .proto
- Add
option go_package = "example.com/gen/apiv1;apiv1";to each proto. - Regenerate so the plugin has an import path.
- Commit the regenerated Go files.
option go_package = "example.com/proto/gen/api/v1;apiv1";Map imports with M arguments
When you cannot edit an imported proto, provide the mapping on the command line as the plugin suggests.
protoc --go_out=. \
--go_opt=Mapi/v1/user.proto=example.com/gen/apiv1 \
api/v1/user.protoHow to prevent it
- Set
go_packagein every proto so codegen is unambiguous. - Use
--go_opt=module=...to strip a common prefix consistently. - Generate through buf.gen.yaml so options are declared once, not per invocation.