Error: Cannot find module 'google-protobuf'

Error: Cannot find module 'google-protobuf'

根据我之前的 ,我正在尝试在 node.js 中使用协议缓冲区。我从 ServiceMessage.proto 生成了 ServiceMessage_pb.js,并添加了以下代码:

var messages = require('./ServiceMessage_pb');

现在我的节点日志中出现以下错误:

Error: Cannot find module 'google-protobuf'
    at Function.Module._resolveFilename (module.js:325:15)
    at Function.Module._load (module.js:276:25)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/home/aii/ws/ServiceMessage_pb.js:8:12)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)

有什么解决办法的建议吗?

谢谢

您可以使用 npm 安装模块:

npm install --save protobuf

然后这样要求:

var my_protobuff = require ("protobuf");
    npm i google-protobuf

我 运行 安装时遇到了很多问题 "protobuf" !

另外官方的protobuf javascript包是"google-protobuf": https://www.npmjs.com/package/google-protobuf