Skip to content

Broken ts imports after moving to grpc-js #70

@ikibalnyi

Description

@ikibalnyi

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions