Issue with importing in VueJS/TypeScript when using gRPC-Web

I have developed a straightforward VueJS application and am currently grappling with incorporating an example for file upload functionality.

The proto file I am utilizing is as follows:

syntax = "proto3";

message File {
  bytes content = 1;
}

message MetaData {
  string name = 1;
  string type = 2;
}

message FileUploadRequest {
  oneof request {
    MetaData metadata = 1;
    File file = 2;
  }
}

enum Status {
  PENDING = 0;
  IN_PROGRESS = 1;
  SUCCESS = 2;
  FAILED = 3;
}

message FileUploadResponse {
  string name = 1;
  Status status = 2;
}

service FileUploadService {
  rpc upload(stream FileUploadRequest) returns(FileUploadResponse);
}

My initial step involves generating the client stub:

protoc -I=${DIR:-./api/} fileUpload.proto \
   --js_out=import_style=commonjs,binary:${OUT_DIR:-./api} \
   --grpc-web_out=import_style=typescript,mode=grpcwebtext:${OUT_DIR:-./api}

This process results in three files being created within the api directory:

├── api
│   ├── FileUploadServiceClientPb.ts
│   ├── fileUpload_pb.d.ts
|   ├── fileUpload.proto
│   └── fileUpload_pb.js
└── src
    ├── App.vue
    └── main
        ├── services
        │   └── fileService.ts
        └── views

My current aim is to integrate the generated client code into the FileService:

import { FileUploadServiceClient } from '../../../api/FileUploadServiceClientPb';
import { FileUploadRequest, FileUploadResponse, MetaData } from '../../../api/fileUpload_pb';

export default class FileService {

    constructor(readonly fileUploadClient: FileUploadServiceClient) { }

    uploadFile(file: File): Promise<FileUploadResponse | null> {
        ...
        this.fileUploadClient.upload(request, {}, (err, response) => {
        ...
        }
        ...
    }
}

I am encountering the following two issues:

  1. The import of messages and types seems to be malfunctioning, yielding a "
    Uncaught SyntaxError: import not found: MetaData
    " error.
  2. Although the import of FileUploadServiceClient is successful, it fails to recognize the upload method.

I am using libprotoc 3.20.1 and protoc-gen-grpc-web 1.3.1

Despite conducting thorough research online, I have been unable to find a solution to address these problems:

Experimenting with different configurations of import_style and mode for grpc-web_out unfortunately did not resolve the issue either. Interestingly, generating server-side code in a Quarkus application functions flawlessly.

Answer №1

I faced challenges with the protoc-gen-grpc-web plugin, but found success with the protobuf-ts plugin which was much easier to work with and actually yielded results: https://github.com/timostamm/protobuf-ts/blob/master/MANUAL.md (This manual provides more information.)

The specific packages I utilized were:

  • @protobuf-ts/runtime
  • @protobuf-ts/plugin (I believe this can be set as a dev dependency)
  • @protobuf-ts/grpcweb-transport (used for creating the transport object required for client creation)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The credentials in AWS S3Client are failing to load correctly

I encountered an issue with the S3 Client from aws sdk v3: When using the S3Client as outlined in the documentation and providing credentials via environment variables, I received an error message stating The AWS Access Key Id you provided does not exist ...

Elevate your Vue JS game by transforming two buttons into a streamlined select drop down menu

I currently have two buttons to sort my array either alphabetically or by relevance, and they are working well. I would like to change these options into a drop-down menu instead of separate buttons. How can I accomplish this? This is what I have right no ...

What is the appropriate method to send a single observable problem to two Observable<boolean>?

Two functions are at play here: this.baseAuthentification.canActivate(route, state) and this.haveDroits(). Both of them return observables. I am looking to return an observable in case this.baseAuthentification.canActivate(route, state) returns false. If ...

Angular 2 is throwing an error, stating that Observable is not defined

I'm currently working with Observable and ChangeDetectionStrategy to notify other components about any changes that occur. However, I am encountering an issue where the Observable object addItemStream is coming up as undefined. Can anyone spot what mi ...

What is the purpose of importing a module in app.module.ts? And what specifically happens when importing classes one by one in the

I am interested in creating an Angular form, but I have a question about why we import 'ReactiveFormsModule' in app.module. Additionally, I am curious as to why we need to explicitly import classes like FormControl and FormGroup again in the temp ...

Transforming a typical JSON file into a parent-child hierarchical JSON structure similar to the one utilized in d3's flare.json file format

My JSON file has a specific structure: { "a": "b", "c": "d", "e": { "f": "g", "h": "i" } } I want to transform it into the following structure: { "name": "Root", "parent": "null", "children": [ { ...

Obtain the template as a string within Vue

Let's examine the scenario of having a single file component in Vue with the following structure: // Article.vue <template> <div> <h1>{{title}}</h1> <p>{{body}}</p> </div> </template> If w ...

Error message: "The use of Vue 3 refs in the render function is

I am facing an issue with my Vue component wherein the root element is set as ref="divRef". Strangely, when I try to access divRef.value inside the onMounted function, it returns undefined. Any assistance on this matter would be greatly appreci ...

Step-by-step guide on building a wrapper child component for a React navigator

When using the Tab.Navigator component, it is important to note that only the Tab.Screen component can be a direct child component. Is there a way in Typescript to convert or cast the Tab.Screen Type to the TabButton function? const App = () => { retur ...

Exploring the methods for monitoring multiple UDP ports on a single address in Node.js within a single process

I am currently working on developing a Node.js application to manage a small drone. The SDK provides the following instructions: To establish a connection between the Tello and a PC, Mac, or mobile device, use Wi-Fi. Sending Commands & Receiving Responses ...

Issue with capturing Vue js events

Recently, I have delved into the world of Vue.js and started working on a checkout form using it. For this project, I am also employing Symfony 31. On the checkout/signup page, there's an embedded collection of forms representing various order items ( ...

display a dual-column list using ngFor in Angular

I encountered a situation where I needed to display data from an object response in 2 columns. The catch is that the number of items in the data can vary, with odd and even numbers. To illustrate, let's assume I have 5 data items to display using 2 co ...

The selection tool in Vue-apexcharts' toolbar is malfunctioning

After creating a line graph with Vue ApexCharts, I attempted to enable the selection tool in the toolbar following the instructions provided at: Despite setting: selection: true, The selection tool does not show up on the graph. Below is my Vue compone ...

What is the reason this union-based type does not result in an error?

In my TypeScript project, I encountered a situation that could be simplified as follows: Let's take a look at the type Type: type Type = { a: number; } | { a: number; b: number; } | { a: number; b: number; c: number; }; I proceed to defi ...

Google Analytics detects an increase in traffic from a specific subdomain

Utilizing Tag Manager, I have successfully added an Analytics tracker to my WordPress site at . However, despite only adding the tracker to the main domain, Analytics is picking up traffic from subdomains like task.mile.app. I am confident that I have onl ...

Why does the error "property undefined" keep popping up even though I've already declared it?

Currently, I am facing an issue with toggling the theme in my project. I am encountering difficulties with the types involved, and I am unsure whether the problem lies within my TypeScript configuration or my actual code itself. I attempted to replicate t ...

Managing optgroup in select dropdown using Angular 4

Is there a way to retrieve the optgroup label value within an onchange function on a select box in Angular 4? In my form, I have a select box with multiple dates as option groups and time slots in 24-hour format for booking (e.g. 1000 for 10AM, 1200 for 1 ...

Creating number inputs in Ionic 2/3 using alerts

I am currently working with Ionic 3.x on my macOS system. The issue I am facing is as follows: I have an array that contains a number and another array consisting of names. table: { number: number, names: string[] } = { number: 0, names: ['& ...

Angular 6 issue: Data not found in MatTableDataSource

Working on implementing the MatTableDataSource to utilize the full functionality of the Material Data-Table, but encountering issues. Data is fetched from an API, stored in an object, and then used to create a new MatTableDataSource. However, no data is b ...

Node.js vulnerability labeled as CVE-2021-38628

Description: Enhance security measures by disabling the use of TLSv1.0 protocol and transitioning to a more secure option like TLSv1.2. To perform a manual test, utilize the following openssl commands: openssl s_client -connect ip:port -tls1. If succes ...