node.js - 尝试使用 Protocol Buffers - Google 的数据交换格式时,goog 未定义错误

标签 node.js module npm protocol-buffers

我正在尝试使用 Protocol Buffers - Google 的数据交换格式,引用 https://github.com/google/protobuf/tree/master/js

我尝试遵循文档,我能够设置协议(protocol)编译器并能够执行

 protoc --js_out=library=myproto_libs,binary:. messages.proto 

但是当我执行 npm install google-protobuf 时,我得到了

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 未定义

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 install 以及 goog.require('com.nec.eva.msap.proto.alerts.FaceAlert'); 是如何进行的;将使用生成的二进制文件,请帮助我几乎花了一天时间来理解但没有得到它

最佳答案

存在问题

the API is not well-documented yet

您需要使用 protoc messages.proto --js_out=import_style=commonjs,binary: 编译它。

或者设置

var jspb = require('google-protobuf')
var goog = jspb

关于node.js - 尝试使用 Protocol Buffers - Google 的数据交换格式时,goog 未定义错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36418217/

相关文章:

node.js - 使全局 NPM 包对 windows 2012 服务器上的所有用户可用

npm - node-sass 漏洞和 npm 审计

node.js - npm Start 和 "npm run client"在 Node 中不工作

angularjs - 套接字 io 的奇怪 cors 问题

node.js - 测试依赖于回调返回的对象的函数调用

javascript - 在jquery ajax中设置从node.js作为二进制数据发送的图像

php - Zend Framework 特定模块中操作的 URL

javascript - 可以将 <script>(或 <style>)标签提取到新的单独文件中的 Gulp 模块

python - 骨架目录的目的

npm - 如何将参数从 npm 命令传递到 Protractor 配置文件