protoc file not found error in generating for dart

460 Views Asked by At

i wanted to generate the protos for dart by

protoc --proto_path=pb/proto --dart_out=lib/api/grpc/pb/gen --plugin=path/to/plugin/.pub-cachce/bin pb/proto/*.proto 

but it says

path/to/project/pb/proto/user.proto: File not found.
path/to/project/pb/proto/product.proto: File not found.
badget.proto:5:1: Import "path/to/project/pb/proto/user.proto" was not found or had errors.
badget.proto:6:1: Import "path/to/project/pb/proto/product.proto" was not found or had errors.
badget.proto:24:3: "packagename.pb.user.Actor" is not defined.
badget.proto:37:3: "packagename.pb.product.Product" is not defined.
badget.proto:65:22: "packagename.pb.user.Actor" is not defined.

!!!i actieved the plugin before that !!! the path to project is not compelete path (its started by the the path configured in setting)

protos=> badgte.proto:

syntax = "proto3";

package packagename.pb.badget;

import "path/to/project/pb/proto/user.proto";
import "path/to/project/pb/proto/product.proto";
import "google/protobuf/timestamp.proto";

blah blah blah;

user.proto:

syntax = "proto3";

package packagename.pb.user;

blah blah blah;

product.proto:

syntax = "proto3";

package packagename.pb.product;

blah blah blah;
1

There are 1 best solutions below

1
On BEST ANSWER

You may need to rearrange things so that the path specified in --proto_path is the parent directory of the paths you use for imports.

Paths in import statements are relative to what you've provided with --proto_path. So for --proto_path=pb/proto and the statement import "path/to/project/pb/proto/user.proto", protoc will be looking for a file "pb/proto/path/to/project/pb/proto/user.proto" which is probably not what you intend.

You might want to consider something like protoc --proto_path=path/to/project, so that your import statements are shorter/more portable:

import "pb/proto/user.proto";

Also, check this to see if it applies to your situation.

Finally, there are some typos in your post (".pub-cachce", "badget" vs. "badgte", etc.) so you may want to check on those as well, in case the typos are present in your actual code.