Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken ts imports after moving to grpc-js #70

Closed
ikibalnyi opened this issue Oct 8, 2020 · 7 comments
Closed

Broken ts imports after moving to grpc-js #70

ikibalnyi opened this issue Oct 8, 2020 · 7 comments

Comments

@ikibalnyi
Copy link
Contributor

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
@agreatfool
Copy link
Owner

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)

@ikibalnyi
Copy link
Contributor Author

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)

@agreatfool
Copy link
Owner

Gotcha, let me have a look.

@ikibalnyi
Copy link
Contributor Author

@agreatfool
Copy link
Owner

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

@ikibalnyi
Copy link
Contributor Author

#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

@agreatfool
Copy link
Owner

Version 5.0.0 has been released. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants