grpc-web icon indicating copy to clipboard operation
grpc-web copied to clipboard

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

Open platput opened this issue 5 years ago • 7 comments

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?

platput avatar Sep 11 '20 05:09 platput

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.

stanley-cheung avatar Sep 11 '20 20:09 stanley-cheung

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.

platput avatar Sep 17 '20 06:09 platput

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.

stanley-cheung avatar Sep 17 '20 21:09 stanley-cheung

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:.

hhanh00 avatar Dec 05 '20 13:12 hhanh00

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

platput avatar Dec 06 '20 06:12 platput

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.

hhanh00 avatar Dec 06 '20 15:12 hhanh00

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

Any updates?

Rednas83 avatar Jan 15 '24 10:01 Rednas83