NodeJS cannot find module 'grpc'

2019-07-31 21:50发布

问题:

Im trying to run a JS script on my raspberry pi 3 but i keep returning to a problem which appears to be the "grpc" module.

i have tried reinstalling and rebulding npm following https://github.com/firebase/firebase-tools/issues/442 som of the proposed answers in this thread, but i keep returning to the same error message as shown below.

Does anyone have experience with firbase running in JS on raspberry pi who know how to fix this, it appears only to be a problem when i have the connection to my firebase in the JS file.

    module.js:557
    throw err;
    ^

Error: Cannot find module 'grpc'
    at Function.Module._resolveFilename (module.js:555:15)
    at Function.Module._load (module.js:482:25)
    at Module.require (module.js:604:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/home/pi/itPDP2018/node_modules/@firebase/firestore/dist/index.node.cjs.js:10:12)
    at Module._compile (module.js:660:30)
    at Object.Module._extensions..js (module.js:671:10)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)

回答1:

The fix for me was to first remove my node_modules from the pi's libary using:

sudo rm -rf node_modules

in my project folder. Then reinstalling the modules with

npm install

but still the grpc module was missing, but installing it with:

sudo npm install grpc

fixed the problem for me.