buf generate - .proto not exists

2.9k Views Asked by At

When I run buf generate, get error:

proto/auth_service.proto:5:8:user.proto: does not exist

buf.gen.yaml:

version: v1
plugins:
  - name: go
    out: gen/go
    opt:
      - paths=source_relative
  - name: go-grpc
    out: gen/go
    opt:
      - paths=source_relative
  - name: grpc-gateway
    out: gen/go
    opt:
      - paths=source_relative
      - generate_unbound_methods=true
  - name: openapiv2
    out: swagger-ui/gen/openapiv2/

The proto files are in proto/, there are only 2 file, 1 file import the other via:

import "user.proto";

So, how to fix this ?

1

There are 1 best solutions below

0
On

After adding buf.work.yaml:

version: v1
directories:
  - proto

now it works.


To find 3rd party dependencies specified via deps

  • Need to add buf.yaml inside the module, aka. the dir contain .proto files. It maybe a sub dir where buf.gen.yaml and buf.work.yaml resides.
  • Seems buf.md should be put in the same dir with buf.yaml, though it doesn't effect the build. It effects the doc on buf.build site.
  • When run buf mod update should be within the dir where buf.yaml exists, or should specify the dir, e.g buf mod update proto/.
  • If u are using goland, install the buf plugin, to make the .proto files able to find the deps in IDE, though it doesn't effects but the build itself.

Refer