Search code examples
grpcprotoc

What am I doing wrong while trying to create a GRPC for web from my proto definition using protoc command in JavaScript?


I'm trying to create a JavaScript from my proto definition.

I'm using this command:

protoc \
--proto_path=./grpc \
--grpc-web_out=mode=grpcwebtext:./lib/gerado/grpc/js/ \
--fatal_warnings interface.proto 

But nothing is generated. And no one message of error is show.
What I'm doing wrong?

I have been tried all kind of approach to solve this.

P.S.: Only now i notice that if in my .proto file there is at least one service, than no output is generated to javascript.


Solution

  • interface.proto:

    syntax = "proto3";
    
    service X {
        rpc Y(Z) returns (Z);
    }
    
    message Z {
    };
    

    With binaries from the releases added to {PATH}:

    And without --js_out:

    protoc \
    --proto_path=${PWD} \
    --grpc-web_out=import_style=commonjs,mode=grpcwebtext:${PWD} \
    ${PWD}/interface.proto
    

    Generates interface_grpc_web_pb.js as expected.

    With --js_out:

    protoc \
    --proto_path=${PWD} \
    --js_out=import_style=commonjs:${PWD} \
    --grpc-web_out=import_style=commonjs,mode=grpcwebtext:${PWD} \
    ${PWD}/interface.proto
    

    Additionally generates interface_pb.js