Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

grpc-reflection doesn't load properly when an imported type doesn't have a package

Aperta
#2,934 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
node.js, typescript
Ambito
api, backend, testing

Direzione di ricerca

Inizia da packages/grpc-reflection/src/implementations/reflection-v1.ts e verifica come vengono risolti i simboli referenziati quando un tipo importato non ha un package. Riproduci il caso usando examples/protos/helloworld.proto e examples/protos/nopackage.proto, quindi confronta il comportamento con packages/grpc-reflection/test/test-reflection-v1-implementation.ts. Il lavoro è completato quando reflection carica la definizione del servizio senza gli avvisi NoPackage, con un test di regressione che copra il caso.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

package: @grpc/reflection
Problem description

When imported type doesn't have a package, and it is used as a field, when I try to enable reflection, first I get these warnings:

Could not find file associated with reference NoPackage

But the gRPC service starts succesfully. However, when trying to load the service definition in Postman I get this error:

Image

Reproduction steps

I modified your reflection example to simulate the problem we have in our code. Please check here. See these 2 files:

  • examples/protos/helloworld.proto
  • examples/protos/nopackage.proto

This is what I get when I run it:

$ node ./reflection/server.js 
Debugger listening on ws://127.0.0.1:53801/5014bd58-6641-4daa-a11b-f7b03f82abcb
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
Could not find file associated with reference NoPackage  <--- these are the warnings in question
Could not find file associated with reference NoPackage
(node:141961) DeprecationWarning: Calling start() is no longer necessary. It can be safely omitted.
(Use `node --trace-deprecation ...` to show where the warning was created)

And if I try to load the definition via reflection in postman, I will get the error on the screenshot above.

Environment
  • OS name, version and architecture: Debian GNU/Linux 12 (bookworm), AMD x64
  • Node version: v20.18.0
  • Node installation method: for this particular example I used npm, but in our project we use yarn
  • Package name and version: @grpc/[email protected]
Additional context

This seem related to this issue: https://github.com/grpc/grpc-node/issues/2671, but sort of in reverse. Instead of removing the dot, I need to add one.

The way I resolved it is by simply checking if there is a reference with a leading dot. See packages/grpc-reflection/src/implementations/reflection-v1.ts in the same branch:

        // if we didn't find anything then try just a FQN lookup
        if (!referencedFile) {
          referencedFile = this.symbols[ref] ?? this.symbols[`.${ref}`];
        }

I would have opened a PR with my change, but I am not sure how to test it. I tried to add a test to packages/grpc-reflection/test/test-reflection-v1-implementation.ts (and updated *.proto files to have the same setup), but regardless of whether this fix is present or not, I get the same content for reflectionService.

But if you rerun the example service with the fix, definition loads via reflection with no issues:
Image

And Postman can even generate some sample request:
Image

Lingua principale
TypeScript
Stelle
4.8k
Fork
716
Merge medio
1g 18h
PR unite (30g)
17

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di grpc/grpc-node

Tutte le issue di grpc/grpc-node

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.