53

I am running my NodeJs App and i am getting an error.

sudo /usr/local/bin/node app.js    
    Error: Failed to load gRPC binary module because it was not installed for the current system
Expected directory: node-v57-linux-x64-glibc
Found: [node-v59-linux-x64-glibc]
This problem can often be fixed by running "npm rebuild" on the current system
Original error: Cannot find module '/home/projects/kj_app/node_modules/grpc/src/node/extension_binary/node-v57-linux-x64-glibc
/grpc_node.node'
    at Object.<anonymous> (/home/projects/kj_app/node_modules/grpc/src/grpc_extension.js:53:17)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/home/projects/kj_app/node_modules/grpc/src/client.js:37:12)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)

Edit

    sudo /usr/local/bin/npm rebuild

    > protobufjs@6.8.6 postinstall /home/projects/kj_app/node_modules/protobufjs
> node scripts/postinstall
> grpc@1.10.1 install /home/projects/kj_app/node_modules/grpc
> node-pre-gyp install --fallback-to-build --library=static_library
[grpc] Success: "/home/projects/kj_app/node_modules/grpc/src/node/extension_binary/node-v59-linux-x64-glibc/grpc_node.node" al
ready installed
Pass --update-binary to reinstall or --build-from-source to recompile
> @google-cloud/profiler@0.1.14 install /home/projects/kj_app/node_modules/@google-cloud/profiler
> node-gyp rebuild
gyp ERR! clean error 
gyp ERR! stack Error: EACCES: permission denied, rmdir 'build'
gyp ERR! System Linux 4.9.0-6-amd64
gyp ERR! command "/opt/bitnami/nodejs/bin/.node.bin" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "
rebuild"
gyp ERR! cwd /home/projects/kj_app/node_modules/@google-cloud/profiler
gyp ERR! node -v v9.8.0
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok 
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @google-cloud/profiler@0.1.14 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the @google-cloud/profiler@0.1.14 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2018-04-10T16_06_40_444Z-debug.log
Sudhanshu Gaur
  • 7,486
  • 9
  • 47
  • 94
  • 3
    It looks like you are trying to run the script with Node 8, but for some reason `npm` thinks it should be installing for Node 9. Also, running these scripts with `sudo` probably isn't helping; you're running in a user directory so you shouldn't need it, and `npm` has some weird behavior when run as root. – murgatroid99 Apr 10 '18 at 18:01
  • 1
    This typically happens when "npm install" is run locally rather than in the container. Any differences, OS, node version become a conflict as constructed grpc module is not built for the right spects. See my comment below for a solution. – DeeZone Oct 01 '19 at 00:46
  • from the functions folder, open command line and enter `npm audit fix` – Ronnie Royston Aug 08 '20 at 03:05

13 Answers13

29

It seems like you have some verion conflict

Expected directory: node-v57-linux-x64-glibc
Found: [node-v59-linux-x64-glibc]

Have you tried running npm rebuild in your app folder?

Tnc Andrei
  • 1,005
  • 10
  • 16
  • Maybe this will help: [node-gyp rebuild errors #809](https://github.com/nodejs/node-gyp/issues/809) – Tnc Andrei Apr 11 '18 at 09:25
  • 1
    It's funny because just as this page was loading I noticed the suggestion in the console logs to run npm rebuild. Hopefully most folks just aren't getting here because they read the output :-D – Methodician Jun 02 '19 at 00:02
19

npm rebuild worked for me :)

Thanx to everyone who replied

(Using n with node v8.15.1 and npm 6.4.1)

guya
  • 5,067
  • 1
  • 35
  • 28
12

I had the same problem (using nvm) and found that my selected node version was different than the one in .nvmrc. I did the following steps to fix it:

rm -rf node_modules
nvm use
yarn

I removed node_modules because it might have installed a version of some dependencies for the wrong version of node, so I want to ensure I have the correct libraries for the selected version.

When I do nvm use, it picks the version of node from the .nvmrc in my project.

You can use npm install instead of yarn. That's just how my project is set up.

Mnebuerquo
  • 5,759
  • 5
  • 45
  • 52
10

I had the same problem with Google Cloud Functions and Emulator, after migration from node 6 to node 8.

My Solution:

  1. npm rebuild // no effect
  2. delete node_modules folder in the functions folder
  3. npm install
  4. in the functions folder call: npm i --save firebase-functions
  5. firebase serve // start the emulator and try
Sean Stayns
  • 4,082
  • 5
  • 25
  • 35
7

By any chance did you do a npm install in your local (node-v59) when it should have been done on the container (node-v57)? The grpc binary is for the wrong version of node thus the error. In the case of the question, it looks like a local Mac (OSX - a flavour of Linux) running linux in a Docker container.

Expected directory: node-v57-linux-x64-glibc
Found: [node-v59-linux-x64-glibc]

The solution would be to rm -fr node_modules and do npm install in the container.

DeeZone
  • 770
  • 7
  • 16
6

Tried npm rebuild and it didn't work for me, what worked is deleting the node_modules and the package-lock.json, and re install node packages using npm install

Amineze
  • 887
  • 11
  • 16
3

After trying many things I ended up doing the following (based on other answer):

  1. Updated node to latest version
  2. Updated npm to latest version
  3. npm rebuild on the project
cristianorbs
  • 670
  • 3
  • 9
  • 16
3

No other answer worked for me. Eventually I fixed it by using the @grpc/grpc-js package instead of grpc

So I've just did

yarn remove grpc
yarn add @grpc/grpc-js

and changed all imports:

# before
import something from 'grpc'
# after
import something from '@grpc/grpc-js'
Florian Ludewig
  • 4,338
  • 11
  • 71
  • 137
2

I had a similar problem (but on the frontend, with Jest, Firebase and NVM). So this might not directly solve the original question but might help others who came here.

Check versions

Try to call these and see if node versions in the paths match:

which node
which npm

In my case also:

which firebase

Webstorm

In my case, I ran into this problem when using Webstorm, Jest, and Firebase, and I wanted to run the tests using Webstorm's tools.

It was a problem with my "Jest Run Configuration". It pointed to a different version of Node than I was using as a default for the system.

exmaxx
  • 3,252
  • 28
  • 27
1

I had the same problem and none of these solutions worked for me. For anyone having a similar lack of success, a more aggressive npm rebuild to force the correct version did it for me: npm rebuild --target=8.15.1 --target_platform=linux --target_arch=x64 --target_libc=glibc (where 8.15.1 is the node version you are using - I believe this is the version used in the original question).

grepx
  • 443
  • 5
  • 7
0

following command worked for me npm rebuild --unsafe-perm --build-from-source Reference: https://docs.oracle.com/en/cloud/paas/blockchain-cloud/user/use-hyperledger-fabric-sdks-develop-applications.html#GUID-59A8279E-7A90-4823-9538-EA236BF9D164

Noor Khan
  • 151
  • 1
  • 9
0

My problem was that I've installed grpc via yarn add grpc on my local machine.

But my code was running inside a Docker container, which had a different node version.

So before my docker-compose.yaml looked like

services:
  server:
    image: node:lts-alpine
    container_name: repro_server
    volumes:
      - ./package.json:/package.json
      - ./yarn.lock:/yarn.lock
      - ./tsconfig.json:/tsconfig.json
      - ./node_modules:/node_modules
      - ./index.ts:/index.ts
    command: yarn run ts-node-dev index

Note, that I was using node_modules from my local machine. The simple fix was to install the node_modules inside the container:

services:
  server:
    image: node:lts-alpine
    container_name: repro_server
    volumes:
      - ./package.json:/package.json
      - ./yarn.lock:/yarn.lock
      - ./tsconfig.json:/tsconfig.json
      - ./index.ts:/index.ts
    entrypoint: sh -c "yarn install --frozen-lockfile && yarn run ts-node-dev index"

Thanks to thesayyn for helping my with this issue!

Florian Ludewig
  • 4,338
  • 11
  • 71
  • 137
0

Solved: After spending a lot of time over this issue, I found the solution and it's tested as well. Just run the below command after install all the required packages along-with grpc.

For Linux & MAC:

sudo npm rebuild --target=8.1.0 --target_platform=linux --target_arch=x64 --target_libc=glibc --update-binary

For Windows:

npm rebuild --target=8.1.0 --target_platform=linux --target_arch=x64 --target_libc=glibc --update-binary
Devendra Rajput
  • 432
  • 7
  • 13