Error: Cannot find module 'google-protobuf'

 ̄綄美尐妖づ 提交于 2019-12-12 03:36:22

问题


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?

Thanks


回答1:


You can install the module with npm:

npm install --save protobuf

Then require it this way:

var my_protobuff = require ("protobuf");



回答2:


    npm i google-protobuf

I run into so many problem installing just "protobuf" !

Also the official protobuf javascript package is "google-protobuf": https://www.npmjs.com/package/google-protobuf



来源:https://stackoverflow.com/questions/36173502/error-cannot-find-module-google-protobuf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!