question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Broken typescript exports after moving to @grpc/grpc-js

See original GitHub issue

Hey,

After updating to @grpc/grpc-js all the exports got changed from export BookService https://github.com/grpc/grpc-node/blob/a5cc154c8e49cf68691880cbddf33456fbbd306a/packages/grpc-tools/src/node_generator.cc#L190 to export['com.book.BookService']. https://github.com/grpc/grpc-node/blob/a5cc154c8e49cf68691880cbddf33456fbbd306a/packages/grpc-tools/src/node_generator.cc#L188 What is the point of such change? Now it’s not possible to generate proper typescript definitions for such exports.

// grpc
import { BookServiceClient } from "./proto/book_grpc_pb";
const client = new BookServiceClient("127.0.0.1:50051", grpc.credentials.createInsecure());

// changed to

// grpc-js
import * as bookGrpcPb from "./proto/book_grpc_pb";
// @ts-ignore
const BookServiceClient = grpc.makeClientConstructor(bookGrpcPb["com.book.BookService"], "BookService");

So now such export is not valid for Typescript and you have to write // @ts-ignore. Why was removed export of the BookServiceClient? or at least BookService?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
murgatroid99commented, Oct 7, 2020

That second line you linked is in the generate_package_definition branch, which is triggered by using the generate_package_definition code generation option. That option makes the generated file export an object that is intended to be loaded using grpc.loadPackageDefinition. You could then apply a TypeScript type to the resulting object.

However, using that option is not the only way to generate code for use with the grpc-js library. You could also use the grpc_js code generation option instead. That will generate code very similar to the code generated without any options, except that it will import @grpc/grpc-js instead of grpc.

0reactions
agreatfoolcommented, Oct 9, 2020

@ikibalnyi OK, thanks. Then I could give the upgrade warning. Next version of ts grpc tool have to be upgraded with grpc-tools version over 1.9.0.

Read more comments on GitHub >

github_iconTop Results From Across the Web

grpc/grpc-js
Start using @grpc/grpc-js in your project by running `npm i ... TypeScript icon, indicating that this package has built-in type declarations.
Read more >
Top 5 @grpc/grpc-js Code Examples
Learn more about how to use @grpc/grpc-js, based on @grpc/grpc-js code examples ... lab = exports.lab = Lab.script(); const { describe, it, before,...
Read more >
does not provide an export named when using vite in grpc- ...
I'm trying to use vite. I've some JavaScript-generated files for GRPC communication; alongside each file, there is a declarative file ...
Read more >
gRPC service in Node.js: Tutorial, Examples and Best ...
JavaScript ; How Nodejs works; REST; API; Client to server communication. We will need the following tools installed in our machine: Nodejs ...
Read more >
What is gRPC ? How to implement gRPC in Node.js
gRPC built on top of Remote Procedure Call and Http/2 with Protocol Buffers. ... and transfer the data over the network. it is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found