thesayyn / protoc-gen-ts

Compile protocol buffer messages to TypeScript.
MIT License
360 stars 74 forks source link

Confusion on generating a .ts file which imports a message from an adjacent file #173

Closed lztetreault-dev closed 8 months ago

lztetreault-dev commented 2 years ago

I'm confused about how to generate a .ts file when I have two Protobufs and one imports a message from the first one.

project layout

project_root/
         protos/
            first.proto
            second.proto

The first file

syntax="proto3";

option go_package="project/thing";
import "google/protobuf/timestamp.proto";

message AType {
    string things = 1;
}

The second file

syntax = "proto3";

option go_package="project/thing";
import "protos/first.proto";

message Something {
   types.AType thing = 1;
}

I am able to generate the first file fine with

protoc -I=protos --ts_out=protos/typescript   first.proto

but the second one complains about a bad import to the first one

protoc -I=protos --ts_out=protos/typescript   second.proto
contact.proto:8:1: Import "protos/first.proto" was not found or had errors.
contact.proto:17:9: "AType" is not defined.

I'm guessing I'm missing something in my command but I am not sure what.

thesayyn commented 2 years ago

-I=protos is the problem here. your imports should be relative to that. so instead of importing withprotos/first.proto use first.proto.