Skip to content

grpc-js: TypeScript Support? #1417

@moloch--

Description

@moloch--

Problem description

I get that grpc-js is a newer library, and there doesn't seem to be any detailed documentation or examples yet of how to use grpc-js so maybe I'm just doing something wrong. I essentially have some proto3 .proto files from an existing project and some gRPC definitions I'd like to use with Node v14 and TypeScript. This doesn't seem possible:

  • proto.Loader doesn't support types, so I need to generate static code files/types
  • pbjs and pbts don't generate gRPC static code
  • proto-gen-ts plug doesn't generate code usable with grpc-js, replacing imports doesn't work
./node_modules/.bin/grpc_tools_node_protoc \
    -I ./protobuf \
    --plugin="protoc-gen-ts=./node_modules/.bin/protoc-gen-ts" \
    --ts_out="service=grpc-node:${OUT_DIR}" \
    --grpc_out="generate_package_definition:${OUT_DIR}" \
    /protobuf/rpc/services.proto

sed -i '' 's/\"grpc\"/\"\@grpc\/grpc-js\"/1' ${OUT_DIR}/rpc/services_grpc_pb.d.ts

Results in:

(node:6297) UnhandledPromiseRejectionWarning: TypeError: services_grpc_pb_1.RPCClient is not a constructor
    at /Users/moloch/git/sliver-script/lib/client.js:452:23
    at new Promise (<anonymous>)
    at Client.connect (/Users/moloch/git/script/lib/client.js:451:16)
    at /Users/moloch/git/sliver-script-test/index.js:50:49
    at step (/Users/moloch/git/script-test/index.js:33:23)
    at Object.next (/Users/moloch/git/script-test/index.js:14:53)
    at fulfilled (/Users/moloch/git/script-test/index.js:5:58)
(Use `node --trace-warnings ...` to show where the warning was created)

Environment

  • MacOS v10.15.4
  • Node v14.x
  • brew

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions