How to load google api dependency?

I’m using google api and protoc-gen-validate as dependency. How can I import these dependencies?

Here are the imports in my proto file:

import "google/api/field_behavior.proto";
import "google/protobuf/any.proto";
import "google/protobuf/empty.proto";
import "validate/validate.proto";

I tried cloning these dependencies from github and import them as this:

const client = new grpc.Client();
client.load(["~/vts-api/vts-idl/proto/vts/api/v1", "~/googleapis/google/api", "~/protoc-gen-validate/validate"], "internal.proto");

But I got error:

ERRO[0000] GoError: internal.proto:12:8: stat /***/protoc-gen-validate/validate/google/api/field_behavior.proto: no such file or directory

There is field_behavior.proto in ~/googleapis/google/api.

Hey @lbaogui :wave:

Welcome to the forum :tada:

I’m not very familiar with the grpc module myself, but could it be that you use the ~ operator in the paths you pass to the load function? I’m not certain that function expands the ~ symbol.

Let me know if that was helpful :bowing_man:

1 Like

I have figured out how to do it. The import paths should be the parent folders of the imported file in proto spec. For example, if in your proto file, you import validate/validate.proto, then the import path should be ~/protoc-gen-validate instead of ~/protoc-gen-validate/validate. I’ve changed to use absolute path in my script. But I think relative path should also work.

2 Likes