Error: Module version mismatch. Expected 48, got 51. at Error (native) at Object.Module._extensions..node (module.js:597:18) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) at Module.require (module.js:497:17) at require (internal/module.js:20:19) at Object.<anonymous> (/home/gang/temp/hfc/test-node-sdk/node_modules/grpc/src/node/src/grpc_extension.js:38:15) at Module._compile (module.js:570:32) at Object.Module._extensions..js (module.js:579:10)
The Node SDK supports Node versions “v6.2.0 - 6.10.0”(Node v7+ is not supported), and I was using node v7.4.0. After I switch node version from v7.4.0 to v6.9.4, the error above is reported. The reason is that: I ran the “npm install” command under Node v7.4.0, whch compiled some modules with Node v7.4.0, which cannnot run under Node v6.9.4. So the fix is just: remove the “node_modules” directory and run the “npm install” command again under Node v6.9.4 again. The will make the node modules be compiled under Node v6.9.4. And the problem is fixed.
Here is my code. And the solution comes from here.
package.json
1 2 3 4 5 6 7 8 9 10 11
{ "name" : "test-node-sdk", "version" : "0.0.1", "description" : "Demo how to use the Hyperledger Fabric node SDK", "main" : "main.js", "author" : "Max Huang", "dependencies" : { "fabric-client" : "1.0.0-rc1", "fabric-ca-client" : "1.0.0-rc1" } }
main.js
1 2 3 4
varClient = require('fabric-client'); var client = newClient(); varOrderer = require('fabric-client/lib/Orderer.js'); var orderer = newOrderer('grpc://localhost:4444');