I'm currently migrating my GRPC service declarations from JS to Typescript and noticed that the code generation is wrong when referencing messages/types from other files.
Given the code below, the following MyServiceServiceClientPb.ts is generated:
...
methodInfoaddOne = new grpcWeb.AbstractClientBase.MethodInfo(
MyMessagesFile_pbInteger,
(request: MyMessagesFile_pbInteger) => {
return request.serializeBinary();
},
MyMessagesFile_pbInteger.deserializeBinary
);
...
Note the correct type is MyMessagesFile_pb.Integer (the dot is missing)!
This is printed in grpc_generator.cc:713.
Using libprotoc 3.11.1 and grpc-web 1.0.7
MyServiceFile.proto
syntax = "proto3";
import "MyMessagesFile.proto";
service MyService {
rpc addOne(Integer) returns (Integer);
}
MyMessagesFile.proto
message Integer {
int32 number = 1;
}
package.json
{
...
"scripts": {
...
"grpc-generate": "mkdir -p src/proto && protoc -I=/path/to/proto/folder /path/to/proto/folder/*.proto --js_out=import_style=commonjs:src/proto --grpc-web_out=import_style=typescript,mode=grpcwebtext:src/proto && for f in src/proto/*.js; do sed -i '1s;^;/* eslint-disable */;' $f; done",
"grpc-generate-macos": "mkdir -p src/proto && protoc -I=/path/to/proto/folder /path/to/proto/folder/*.proto --js_out=import_style=commonjs:src/proto --grpc-web_out=import_style=typescript,mode=grpcwebtext:src/proto && for f in src/proto/*.js; do sed -i '' '1s;^;/* eslint-disable */;' $f; done",
...
}
...
}
This is happening to us too. Extremely annoying... I guess I'm fixing it with sed for now?
That’s how I’m approaching it. Since I don’t generate the files too often, and I don’t have that many, it’s not too bad to do it.
Fixing it does not look too hard, but I don’t have the bandwidth to tackle it at the moment.
If you end up creating a generic-enough script to use as workaround, please post it here for everyone. :)
João
On 12 Feb 2020, at 04:40, Jason Banich notifications@github.com wrote:

This is happening to us too. Extremely annoying... I guess I'm fixing it with sed for now?—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
This is happening to us too. Extremely annoying... I guess I'm fixing it with sed for now?
Affecting me too... can you share your sed expression @Jdban?
Affecting me too... can you share your
sedexpression @Jdban?
Sure, it's not very generic though. It's just doing an explicit find/replace on the string in all the .ts files.
in our bash script:
# Handles this annoying bug: https://github.com/grpc/grpc-web/issues/693
ORIGINAL=shared_pbFilterRequest
REPLACEMENT=shared_pb.FilterRequest
grep -l -E "$ORIGINAL" **/*.ts | xargs sed -i.bak "s#$ORIGINAL#$REPLACEMENT#g"
rm -rf js/*.bak # Our files are in a js folder
Most helpful comment
Sure, it's not very generic though. It's just doing an explicit find/replace on the string in all the .ts files.
in our bash script: