whisklabs / grpc-ts

Whisk GRPC web library
MIT License
31 stars 3 forks source link

No found message or enum for google.protobuf.Duration or google.protobuf.Timestamp #12

Open cayden-uw opened 2 years ago

cayden-uw commented 2 years ago

When running npx @whisklabs/grpc on my proto file I get errors for every duration and timestamp field like the error below

No found message or enum: uwGrpc_google_protobuf_Duration [in "uwGrpc_IntValueDuration" field "duration = 2"]

I compared my proto to the one in your tests which uses timestamps and couldn't find any differences in imports or the one the fields are defined.

I am using Ubuntu 21.10, I have protoc installed and can successfully generate js libaries using protoc grpc-web

askuzminov commented 2 years ago

@cayden-uw Can you show an example of a proto file?

Did you add this file to the project? google/protobuf/duration.proto and google/protobuf/timestamp.proto

protoc grpc-web automatically add package google.protobuf from here: https://github.com/protocolbuffers/protobuf/tree/master/src/google/protobuf

Our library generates clean code to control what needs to be turned on. Perhaps there is a need to add package google.protobuf by default too.

stephennancekivell commented 2 years ago

Hi, I've made a minimal reproduction that shows the issue.

syntax = "proto3";

import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto";

message Sample {
  string value_a = 1;
  google.protobuf.Timestamp value_b = 2;
  google.protobuf.Duration value_c = 3;
}

When I run it

PROTO_DIR=mini/ PROTO_OUT=whisk npx @whisklabs/grpc
No found message or enum: google_protobuf_Timestamp [in "Sample" field "value_b = 2"]
No found message or enum: google_protobuf_Duration [in "Sample" field "value_c = 3"]

If I comment out value_b & value_c it runs.

Is there some other way to import packages or something?

PS, thanks for the lib 😊

stephennancekivell commented 2 years ago

Found a workaround.

From the same sample message definition.

First download the Timestamp and Duration definitions and put them in the same folder.

curl https://raw.githubusercontent.com/protocolbuffers/protobuf/master/src/google/protobuf/duration.proto -o mini/duration.proto
curl https://raw.githubusercontent.com/protocolbuffers/protobuf/master/src/google/protobuf/timestamp.proto -o mini/timestamp.proto

Then run it.

PROTO_DIR=mini/ PROTO_OUT=whisk npx @whisklabs/grpc

This gives output with an index.js like.

// Code created by generator @whisklabs/grpc
// https://github.com/whisklabs/grpc-ts
// Version: 1.1.1
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.google_protobuf_Timestamp = exports.Sample = exports.google_protobuf_Duration = void 0;
function google_protobuf_Duration() {
    return [
        [1, "seconds", "int64", 1],
        [2, "nanos", "int32", 1],
    ];
}
exports.google_protobuf_Duration = google_protobuf_Duration;
function Sample() {
    return [
        [1, "valueA", "string", 1],
        [2, "valueB", google_protobuf_Timestamp, 0],
        [3, "valueC", google_protobuf_Duration, 0],
    ];
}
exports.Sample = Sample;
function google_protobuf_Timestamp() {
    return [
        [1, "seconds", "int64", 1],
        [2, "nanos", "int32", 1],
    ];
}
exports.google_protobuf_Timestamp = google_protobuf_Timestamp;

Ideally, the library would know how to resolve these dependencies like the other proto generators.

Thanks