0

I have a simple nodejs client that uses grpc and protobuf to talk to a cpp grpc server. My package.json contains the required packages:

"dependencies": {
       "google-protobuf": "^3.9.1",
       "grpc-web": "^1.0.6",
       "webpack": "^4.39.2",
      "webpack-cli": "^3.3.7"
    }

I ran npm install and all the modules were installed in locally node_modules.

My client in in the same path as node_modules but when I launch it, I get an error saying that it cannot find the protobuf module.

From client.js:

var messages  = require('../../messages/proto/output/work_pb.js');
var services  = require('../../messages/proto/output/work_grpc_web_pb.js');
var grpc      = require('grpc');

Running the client:

node client.js
Error: Cannot find module 'google-protobuf'
Require stack:
- /home/work/messages/proto/output/work_pb.js
- /home/work/frontend/web/client.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:713:15)
    at Function.Module._load (internal/modules/cjs/loader.js:618:27)
    at Module.require (internal/modules/cjs/loader.js:771:19)
    at require (internal/modules/cjs/helpers.js:68:18)
    at Object.<anonymous> (/home/radu/work/admass/messages/proto/output/work_pb.js:11:12)
    at Module._compile (internal/modules/cjs/loader.js:868:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:879:10)
    at Module.load (internal/modules/cjs/loader.js:731:32)
    at Function.Module._load (internal/modules/cjs/loader.js:644:12)
    at Module.require (internal/modules/cjs/loader.js:771:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/home/work/messages/proto/output/work_pb.js',
    '/home/work/frontend/web/client.js
codentary
  • 993
  • 1
  • 14
  • 33

2 Answers2

0

Removing the entire node_modules folder and re-installing will work:

rm -rf node_modules
npm install 
Bivin Vinod
  • 2,210
  • 1
  • 12
  • 15
  • My issue is related to the fact that I have the `../../messages/proto/output/work_pb.js` in some other path, and I think node tries to find the modules there. I need to tell node to look in the current dir. – codentary Aug 19 '19 at 08:51
0

I ended up adding the node module inside '../../messages/ and removing it from pace where the proto files are being referenced, as to avoid conflicts.

codentary
  • 993
  • 1
  • 14
  • 33