Hyperledger Fabric: Error: Failed to load gRPC binary module because it was not installed for the current system

Table of Contents

Problem

I was following this Hyperledger Fabric tutorial: Writing your First Application

This tutorial demonstrates a Hyperledger Fabric Sample Application named FabCar. Here’s the github repository of the fabcar sample app: https://github.com/hyperledger/fabric-samples/tree/master/fabcar

I went inside the fabric-samples/fabcar directory and I was able to run the startFabric shell script:


./startFabric.sh

After that, I tried to enroll the admin user by running the following command:


node enrollAdmin.js

When I ran the above command, I got the following error:

/home/mukesh/Hyperledger/fabric/fabric-samples/fabcar/node_modules/fabric-client/node_modules/grpc/src/grpc_extension.js:55
throw error;
^

Error: Failed to load gRPC binary module because it was not installed for the current system
Expected directory: node-v64-linux-x64-glibc
Found: [node-v57-linux-x64-glibc]
This problem can often be fixed by running “npm rebuild” on the current system
Original error: Cannot find module ‘/home/mukesh/Hyperledger/fabric/fabric-samples/fabcar/node_modules/fabric-client/node_modules/grpc/src/node/extension_binary/node-v64-linux-x64-glibc/grpc_node.node’
at Object. (/home/mukesh/Hyperledger/fabric/fabric-samples/fabcar/node_modules/fabric-client/node_modules/grpc/src/grpc_extension.js:53:17)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object. (/home/mukesh/Hyperledger/fabric/fabric-samples/fabcar/node_modules/fabric-client/node_modules/grpc/src/client.js:37:12)
at Module._compile (internal/modules/cjs/loader.js:689:30)

Cause

The cause of this error is a bit tricky. The error shows that the cause might be gRPC node module. But, the actual reason for this error is the incompatible npm and node version in your computer.

I had the current latest version of node and npm:

node version 10.9.0
npm version 6.4.0

But, the current Hyperledger Fabric (release version 1.2) Prerequisites says that there should be:

node version 8.9.x or greater (but not 9.x or 10.x)
npm version 5.6.0

Solution

To solve this error, we need to downgrade or set the node and npm version to the one specified in the Prerequisites.

Set NPM version to 5.6.0


npm install npm@5.6.0 -g

Check NPM version


npm -v

Set Nodejs version to 8.9.4

– The Prerequisites says that the node version should be 8.9.x or greater.
– But, it should be in the range of 8.9.x.
– Node version 9.x or 10.x will give the same error.
– Therefore, we set the node version to 8.9.4. This version has worked well in my case.

Install NVM (Node Version Manager)

To set a specific node version, at first, we will install NVM (Node Version Manager).

You can run the nvm install script using either cURL or Wget.

using cURL:


curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash

or Wget:


wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash

The script clones the nvm repository to ~/.nvm directory and adds the required source line to your profile (~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc).

Now, open a new window or new tab in the terminal.

List out the commands available for nvm:


nvm --help

Install and use specific node version using nvm

In our case, we will install and use node version 8.9.4.


nvm install v8.9.4
nvm use 8.9.4

After that, check the node version:

Check node version


node -v

Now, when your node version is set to 8.9.4 and npm version is set to 5.6.0, then you can run the enrollAdmin.js file and it should run successfully without any error.


node enrollAdmin.js

Hope this helps. Thanks.