错误:找不到模块"google-protobuf" [英] Error: Cannot find module 'google-protobuf'

查看:1574
本文介绍了错误:找不到模块"google-protobuf"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按照我之前的问题,我正在尝试在node.js中使用协议缓冲区.我已经从ServiceMessage.proto生成了ServiceMessage_pb.js,并添加了以下代码:

Following to my previous question, I'm trying to use protocol buffers in node.js. I've generated ServiceMessage_pb.js from my ServiceMessage.proto, and add the following code:

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

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

Now I'm getting the following error in my node log:

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)

任何建议如何解决这个问题?

Any suggestions how to solve this?

谢谢

推荐答案

您可以使用npm安装模块:

You can install the module with npm:

npm install --save protobuf

然后以这种方式要求它:

Then require it this way:

var my_protobuff = require ("protobuf");

这篇关于错误:找不到模块"google-protobuf"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆