grpc / grpc-web

gRPC for Web Clients
https://grpc.io
Apache License 2.0
8.65k stars 764 forks source link

Error in the generated proto file in grpc-web saying proto is not defined #954

Open platput opened 4 years ago

platput commented 4 years ago

Hello, I am trying to run grpc-web with nuxtjs. The issue I am facing only happens when I run "npm run dev". Its not happening if I run "npm run build and npm run start" ie, production mode.

I have included all the files and when I run it and try to access the webpage, it shows this error "proto is not defined." This error is coming from the generated proto files by the protoc command.

Could anyone point me in the right direction to solve this issue?

stanley-cheung commented 4 years ago

You are most likely missing a step to compile your .js files before using them. See https://github.com/grpc/grpc-web/tree/master/net/grpc/gateway/examples/helloworld#compile-the-client-javascript-code.

platput commented 4 years ago

I don't see any such build steps. I am using nuxt and in dev mod the only command I have to run is npm run dev. So I don't get which step I am missing sadly.

stanley-cheung commented 4 years ago

Sorry I don't know what nuxtjs does. But you may want to follow our helloworld example to see if you can bring up an end-to-end example that way, and then see what you are missing.

hhanh00 commented 3 years ago

In the part where you compile the proto files to js, you need to specify the commonjs_strict style. For example,

protoc -I=../proto hello.proto --js_out=import_style=commonjs_strict:. --grpc-web_out=import_style=commonjs,mode=grpcwebtext:.
platput commented 3 years ago

Did that. But now it shows this error: "Cannot read property 'deserializeBinary' of undefined"

hhanh00 commented 3 years ago

I think something is not right with the code generated when using a package name.

I removed the package line in the proto file and added

option java_package = "com.example";

For the record, the code generated was proto.helloworld.HelloReply.deserializeBinary but somehow there is an additional level of nesting. The function is proto.helloworld.helloworld.HelloReply.deserializeBinary which does not seem to be intended.

I think line 19 of the helloworld_grpc_web_pb.js should just be

proto = require('./helloworld_pb.js');

Btw, there seems to be other issues with protobuf, commonjs_strict and package names.

Rednas83 commented 10 months ago

I am currently also looking into setting up grpc-web with a nuxt/vue/typescript application.

Any updates?