[英]TypeError: Cannot read properties of undefined (reading 'MethodInfo') in react js app using grpc-web
I am using grpc-web to communicate with a java backend over gRPC.我正在使用 grpc-web 通过 gRPC 与 java 后端通信。 I am using ReactJS on the frontend which uses grpc-web to interpret the protobuffers.我在前端使用 ReactJS,它使用 grpc-web 来解释 protobuffers。
I am getting this strange error.我收到这个奇怪的错误。 My protos are correct ( I checked using a reflection tool called "bloom" so the backend is just fine) This somehow seems like an error internal to the grpc libraries I am using in ReactJS.我的原型是正确的(我使用名为“bloom”的反射工具进行了检查,因此后端很好)这在某种程度上似乎是我在 ReactJS 中使用的 grpc 库的内部错误。
I get the following error:我收到以下错误:
TypeError: Cannot read properties of undefined (reading 'MethodInfo')
The above error points to my proto file: dashboard_services_grpc_web_pb.js上面的错误指向我的 proto 文件: dashboard_services_grpc_web_pb.js
In this file, it point to this line在这个文件中,它指向这一行
const methodInfo_DashboardService_userLogin = new grpc.web.AbstractClientBase.MethodInfo( ...... );
I have a hard time solving this because according to my understanding, grpc.web.AbstractClientBase
is something native to grpc-web
.我很难解决这个问题,因为根据我的理解, grpc.web.AbstractClientBase
是grpc-web
原生的东西。
I have also reinstalled my node_modules in hopes that this is a version issue but no avail.我还重新安装了我的 node_modules,希望这是一个版本问题,但无济于事。
I had the same issue because I was using an old release of the executable protoc-gen-grpc-web
with respect to the current version of grpc-web
.我遇到了同样的问题,因为我使用的是旧版本的可执行文件protoc-gen-grpc-web
相对于当前版本的grpc-web
。 Using version 1.3.0 for both solved the issue for me.使用 1.3.0 版为我解决了这个问题。 You can download the latest release of protoc-gen-grpc-web
here .您可以在此处下载protoc-gen-grpc-web
的最新版本。
In my case it was happening after cache clear, because we had:就我而言,它是在清除缓存后发生的,因为我们有:
"grpc-web": "^1.2.1",
and it was installed version 1.3.0
I changed it to:它安装了1.3.0
版,我将其更改为:
"grpc-web": "1.2.1",
and yarn
again to fix this issue!和yarn
再次解决这个问题!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.