2

I've come across the need to import one file into another, but I can't find a clear explanation of how to do it.

So, I have my index proto file using some message from common.proto. All proto files lie in the same directory.

index.proto:

syntax = "proto3";

import "common.proto";

package index;

common.proto:

syntax = "proto3";

package common;

message Void {}

And I receive message: " Cannot resolve import 'common.proto' "

wh4y
  • 33
  • 1
  • 5

2 Answers2

0

Have you already tried to set the --proto_path flag? I tried it in my environment and what I think you are missing is telling Protobuf the location of your files

Here you can find the documentation: https://developers.google.com/protocol-buffers/docs/proto3#importing_definitions

Anditthas
  • 531
  • 1
  • 3
  • 11
  • 1
    @wh4y I think they use this flag under the hood, I use WebStorm as well and I knew I had to set it in the beginning. Happy Coding :) – Anditthas Apr 20 '22 at 11:59
0

Try loading all proto files from a directory instead, using includeDirs

An example :

app.connectMicroservice({
transport: Transport.GRPC,
options: {
  package: 'sample.user',
  protoPath: '/sample/user/user.proto',
  loader: {
    includeDirs: [join(__dirname, '..', 'protos')], // will load all proto files in the diectory 'protos'
  },
},
});
bareMetal
  • 425
  • 1
  • 7
  • 20