0

Could somebody help. I have such project structure and my node app complaints about this generated file(error_pb.js). In index.js with 'google-protobuf' I do not have such problem. Is there ideas how to solve it?

my_prj\src\server> node .

internal/modules/cjs/loader.js:883
  throw err;
  ^

Error: Cannot find module 'google-protobuf'
Require stack:
- \my_prj\gen\js\proto\error_pb.js
- \my_prj\src\server\modules\requestHandlers\topicHandler.js   
- \my_prj\src\server\index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (\my_prj\gen\js\proto\error_pb.js:14:12)

thanks in advance.

user1578679
  • 29
  • 1
  • 3
  • `npm i google-protobuf` and `const google-protobuf = require('google-protobuf')` in the index.js file. – Apoorva Chikara Apr 14 '21 at 14:45
  • @ApoorvaChikara google-protobuf is already installed in the project. problem related to the files which not in server folder. i need somehow adjust search paths – user1578679 Apr 14 '21 at 17:09
  • Can you add more details to the question where exactly the problem or what is the problem? – Apoorva Chikara Apr 14 '21 at 17:10
  • @ApoorvaChikara The file \my_prj\gen\js\proto\error_pb.js contains line: require('google-protobuf') inside. And nodejs complaints about it. error_pb.js is auto-generated so no change inside. Moreover the file located in different folder, a few levels up: \my_prj\gen\js\proto\error_pb.js <->\my_prj\src\server\index.js. All files related to the server side located in my_prj\src\server(node_modules, index.js, package.json, ...) except auto-generated. So is it possible to having such folder structure and fix this issue? – user1578679 Apr 14 '21 at 17:48
  • Why don't you provide the relative path to this file manually once the file is generated or it is automatically generated new everytime? – Apoorva Chikara Apr 14 '21 at 17:59
  • @ApoorvaChikara relative path to error_pb.js is specified. Nodejs can find error_pb.js. the file can be generated each time new. – user1578679 Apr 15 '21 at 06:03
  • check [this](https://stackoverflow.com/questions/9023672/how-do-i-resolve-cannot-find-module-error-using-node-js#:~:text=This%20error%20can%20be%20encountered,an%20entrypoint%20to%20your%20module.). – Apoorva Chikara Apr 15 '21 at 06:05
  • 1
    thank for the link. I already saw this topic before. Probably i will change folder structure and it will solve the problem. – user1578679 Apr 16 '21 at 11:38
  • You can try that if it solves the problem. – Apoorva Chikara Apr 16 '21 at 11:40

0 Answers0