Search code examples
protocgrpc-web

Issue with TypeScript definition files when generating proto definitions with protoc-gen-grpc-web


I'm having an issue with my generated proto definitions.

I'm using the most up to date version of the protoc-gen-grpc-web which I got from here (version 1.0.7).

Note: I've had the same problem on both MacOS and Windows as well as on version 1.0.5.

The problem I have is my generated definitions are missing the . separating the Class from its namespace.

Eg. my output would be something as follows:

import * as jspb from "google-protobuf"

import * as google_protobuf_timestamp_pb from 'google-protobuf/google/protobuf/timestamp_pb';
import * as google_protobuf_empty_pb from 'google-protobuf/google/protobuf/empty_pb';
import * as common_basic_pb from './common/basic_pb';
import * as contact_mechanism_pb from './contact_mechanism_pb';
import * as banking_detail_pb from './banking_detail_pb';
...

export namespace IncomeTax {
  export type AsObject = {
    id: string,
    personId: string,
    dateCreated?: google_protobuf_timestamp_pb.Timestamp.AsObject,
    lastUpdated?: google_protobuf_timestamp_pb.Timestamp.AsObject,
    fromDate?: google_protobuf_timestamp_pb.Timestamp.AsObject,
    thruDate?: google_protobuf_timestamp_pb.Timestamp.AsObject,
    taxNumber: string,
    country?: contact_mechanism_pbCountry.AsObject,
  }
}

See the line country?: contact_mechanism_pbCountry.AsObject,.

contact_mechanism_pbCountry should be contact_mechanism_pb.Country.

This happens for every case of common_basic_pb, contact_mechanism_pb and banking_details_pb.

But not for the cases of google_protobuf_timestamp_pb and google_protobuf_empty_pb.

Here is what my gen-protos script looks like:

#!/bin/bash

mkdir -p ./src/gen

protoc -I=../protos/                                   \
       ../protos/*.proto                               \
       ../protos/**/*.proto                            \
       ../protos/**/**/*.proto                         \
       ../protos/**/**/**/*.proto                      \
       --js_out=import_style=commonjs:./src/gen \
       --grpc-web_out=import_style=commonjs+dts,mode=grpcwebtext:./src/gen

I've tried so many different things but I just can't get the expected output with this tool.


Solution

  • This issue has been resolved by a fix which was merged into the project 29 days ago. The project owners have announced that they will make a new release soon.

    More details around that can be found here.

    The new release of the tool will be version 1.0.8