尝试使用协议缓冲区时未定义 goog 错误 - Google 的数据交换格式 [英] goog is not defined error while trying to use Protocol Buffers - Google's data interchange format
问题描述
我正在尝试使用协议缓冲区 - 谷歌的数据交换格式参考 https://github.com/google/protobuf/tree/master/js
I am trying to use Protocol Buffers - Google's data interchange format referring https://github.com/google/protobuf/tree/master/js
我试图按照文档我能够获得协议编译器的设置并能够做到
I tried to follow documentation i am able to get the setup of Protocol Compiler and able to do
protoc --js_out=library=myproto_libs,binary:. messages.proto
但是当我执行 npm install google-protobuf 时,我得到了
but when i do npm install google-protobuf i am getting
npm ERR! 404 Registry returned 404 for GET on https://registry.npmjs.org/google-
npm ERR! 404
npm ERR! 404 'google-protobuf' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.
如果我写的样本可以使用生成的二进制文件,它会说没有定义 goog
and if i write the sample which can use that generated binary it says goog is not defined
goog.require('com.nec.eva.msap.proto.alerts.FaceAlert');
var message = com.nec.eva.msap.proto.alerts.FaceAlert();
message.watchlist_id("1");
message.candidate_id("25");
message.gender("female");
bytes = message.serializeBinary();
我不知道为什么我不能安装 npm 以及 goog.require('com.nec.eva.msap.proto.alerts.FaceAlert');将使用生成的二进制文件,请帮助我几乎花了一天的时间来理解但没有得到它
I am not sure why i am not able to do npm install and also how that goog.require('com.nec.eva.msap.proto.alerts.FaceAlert'); will use the generated binary please help i have almost spent a day to understand but not getting it
推荐答案
存在问题
API 没有很好的文档记录
你需要用 protoc messages.proto --js_out=import_style=commonjs,binary: 编译它.
或者设置
var jspb = require('google-protobuf')
var goog = jspb
这篇关于尝试使用协议缓冲区时未定义 goog 错误 - Google 的数据交换格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!