agreatfool / grpc_tools_node_protoc_ts

Generate TypeScript d.ts definitions for generated js files from grpc_tools_node_protoc

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Broken ts imports after moving to grpc-js

ikibalnyi opened this issue · comments

Spent some time trying to figure out how to fix broken typescript imports after switching to @grpc/grpc-js. And the doc is actually wrong. In order for generated js to keep having BookServiceClient export instead of exports['com.book.BookService'] and at the same time using new @grpc/grpc-js you have to change:

--grpc_out=generate_package_definition:$OUT_DIR

to

--grpc_out=grpc_js:$OUT_DIR

then the only difference of the generated js file would be the import from @grpc/grpc-js. All the exports would remain the same.


Here is the whole generation script that's using grpc-js:

PROTOC="$(yarn bin)/grpc_tools_node_protoc"

# path to proto files
PROTO_PATH=./proto/*.proto
# path to generated files
OUT_DIR=./generated

$PROTOC \
  --js_out=import_style=commonjs,binary:$OUT_DIR \
  --grpc_out=grpc_js:$OUT_DIR \
  --ts_out=generate_package_definition:$OUT_DIR \
  $PROTO_PATH

Could you please tell me where did you find the flag "grpc_js"? I googled around, and only found "generate_package_definition" as the official recommended option, see: grpc/grpc-node#931 (comment)

In the comment it says that it's needed for grpc.loadPackageDefinitions.

Here I've opened an issue in their repo: grpc/grpc-node#1600 (comment)

Gotcha, let me have a look.

Yeah, I've just saw it. But it's too simple. I would make some test to see what I can do next.

#71 Opened a small PR adding support for grpc_js, so that we could have consistent flags.

  --grpc_out=grpc_js:$OUT_DIR \
  --ts_out=grpc_js:$OUT_DIR

Version 5.0.0 has been released. Thanks.