2

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

Community
  • 1
  • 1
ItayB
  • 10,377
  • 9
  • 50
  • 77
  • `npm.org` does not list any module named `google-protobuf`. Probably it has been moved, renamed or is published elsewhere. – S.D. Mar 23 '16 at 09:05
  • @S.D there is https://www.npmjs.com/package/protobuf **This is a fork of http://code.google.com/p/protobuf-for-node/** – Luke Mar 23 '16 at 09:17
  • There is a require statement at line 8 of ServiceMessage_pb.js that specifically requires google-protobuf. It looks like the generator of this file uses google-protobuf, while actual module is protobuf. – S.D. Mar 25 '16 at 08:26

2 Answers2

6
    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

Rabhi salim
  • 486
  • 5
  • 17
1

You can install the module with npm:

npm install --save protobuf

Then require it this way:

var my_protobuff = require ("protobuf");
Jamesking56
  • 3,683
  • 5
  • 30
  • 61
Luke
  • 1,768
  • 2
  • 20
  • 30
  • Can you look at my prev question (link above) - I've download the source code, compiled it & install.. I don't think I should do it again. I'll try your second suggestion about the require and update soon.. 10x – ItayB Mar 23 '16 at 09:11
  • you don't need to compile the source code yourself. Just use npm – Luke Mar 23 '16 at 09:16
  • can you post the directory structure of your project? – Luke Mar 23 '16 at 12:01
  • I think it all unstable because I'm using v3.0.0 beta... I'll try to downgrade to 2.6 - thanks anyway.. – ItayB Mar 23 '16 at 17:12
  • 2
    `WARNING` This is NOT the official google package. See other answers. – WSBT Mar 04 '21 at 15:51