hypeledger fabric JavaScript-application node app.js does not work

Viewed 125

I am new to the blockchain field and I try to run sample network from Hyperledger network follow this documentation . I started download the prerequisite and get every things right .

The network is working and deploy it using JavaScript after all the channel and deployment I cd into the JavaScript-application to run the app.js as the documentation said but I got this error

node app
node:internal/modules/cjs/loader:944
  throw err;
  ^

Error: Cannot find module 'pkcs11js'
Require stack:
- D:\fifthLevel\blockchain\hyperledger\try-fabric-network\go\src\github.com\FatimaAlmashhor\fabric-samples\asset-transfer-basic\application-javascript\node_modules\fabric-common\lib\impl\bccsp_pkcs11.js
- D:\fifthLevel\blockchain\hyperledger\try-fabric-network\go\src\github.com\FatimaAlmashhor\fabric-samples\asset-transfer-basic\application-javascript\node_modules\fabric-common\lib\User.js
- D:\fifthLevel\blockchain\hyperledger\try-fabric-network\go\src\github.com\FatimaAlmashhor\fabric-samples\asset-transfer-basic\application-javascript\node_modules\fabric-common\index.js
- D:\fifthLevel\blockchain\hyperledger\try-fabric-network\go\src\github.com\FatimaAlmashhor\fabric-samples\asset-transfer-basic\application-javascript\node_modules\fabric-network\lib\logger.js
- D:\fifthLevel\blockchain\hyperledger\try-fabric-network\go\src\github.com\FatimaAlmashhor\fabric-samples\asset-transfer-basic\application-javascript\node_modules\fabric-network\lib\impl\query\query.js
- D:\fifthLevel\blockchain\hyperledger\try-fabric-network\go\src\github.com\FatimaAlmashhor\fabric-samples\asset-transfer-basic\application-javascript\node_modules\fabric-network\lib\transaction.js
- D:\fifthLevel\blockchain\hyperledger\try-fabric-network\go\src\github.com\FatimaAlmashhor\fabric-samples\asset-transfer-basic\application-javascript\node_modules\fabric-network\lib\contract.js
- D:\fifthLevel\blockchain\hyperledger\try-fabric-network\go\src\github.com\FatimaAlmashhor\fabric-samples\asset-transfer-basic\application-javascript\node_modules\fabric-network\lib\network.js
- D:\fifthLevel\blockchain\hyperledger\try-fabric-network\go\src\github.com\FatimaAlmashhor\fabric-samples\asset-transfer-basic\application-javascript\node_modules\fabric-network\lib\gateway.js
- D:\fifthLevel\blockchain\hyperledger\try-fabric-network\go\src\github.com\FatimaAlmashhor\fabric-samples\asset-transfer-basic\application-javascript\node_modules\fabric-network\index.js
- D:\fifthLevel\blockchain\hyperledger\try-fabric-network\go\src\github.com\FatimaAlmashhor\fabric-samples\asset-transfer-basic\application-javascript\app.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:941:15)
    at Function.Module._load (node:internal/modules/cjs/loader:774:27)   
    at Module.require (node:internal/modules/cjs/loader:1013:19)
    at require (node:internal/modules/cjs/helpers:93:18)
    at Object.<anonymous> (D:\fifthLevel\blockchain\hyperledger\try-fabric-network\go\src\github.com\FatimaAlmashhor\fabric-samples\asset-transfer-basic\application-javascript\node_modules\fabric-common\lib\impl\bccsp_pkcs11.js:27:18)
    at Module._compile (node:internal/modules/cjs/loader:1109:14)        
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1138:10)
    at Module.load (node:internal/modules/cjs/loader:989:32)
    at Function.Module._load (node:internal/modules/cjs/loader:829:14)   
    at Module.require (node:internal/modules/cjs/loader:1013:19) {       
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'D:\\fifthLevel\\blockchain\\hyperledger\\try-fabric-network\\go\\src\\github.com\\FatimaAlmashhor\\fabric-samples\\asset-transfer-basic\\application-javascript\\node_modules\\fabric-common\\lib\\impl\\bccsp_pkcs11.js',
    'D:\\fifthLevel\\blockchain\\hyperledger\\try-fabric-network\\go\\src\\github.com\\FatimaAlmashhor\\fabric-samples\\asset-transfer-basic\\application-javascript\\node_modules\\fabric-common\\lib\\User.js',
    'D:\\fifthLevel\\blockchain\\hyperledger\\try-fabric-network\\go\\src\\github.com\\FatimaAlmashhor\\fabric-samples\\asset-transfer-basic\\application-javascript\\node_modules\\fabric-common\\index.js',
    'D:\\fifthLevel\\blockchain\\hyperledger\\try-fabric-network\\go\\src\\github.com\\FatimaAlmashhor\\fabric-samples\\asset-transfer-basic\\application-javascript\\node_modules\\fabric-network\\lib\\logger.js',       
    'D:\\fifthLevel\\blockchain\\hyperledger\\try-fabric-network\\go\\src\\github.com\\FatimaAlmashhor\\fabric-samples\\asset-transfer-basic\\application-javascript\\node_modules\\fabric-network\\lib\\impl\\query\\query.js',
    'D:\\fifthLevel\\blockchain\\hyperledger\\try-fabric-network\\go\\src\\github.com\\FatimaAlmashhor\\fabric-samples\\asset-transfer-basic\\application-javascript\\node_modules\\fabric-network\\lib\\transaction.js',  
    'D:\\fifthLevel\\blockchain\\hyperledger\\try-fabric-network\\go\\src\\github.com\\FatimaAlmashhor\\fabric-samples\\asset-transfer-basic\\application-javascript\\node_modules\\fabric-network\\lib\\contract.js',     
    'D:\\fifthLevel\\blockchain\\hyperledger\\try-fabric-network\\go\\src\\github.com\\FatimaAlmashhor\\fabric-samples\\asset-transfer-basic\\application-javascript\\node_modules\\fabric-network\\lib\\network.js',
    'D:\\fifthLevel\\blockchain\\hyperledger\\try-fabric-network\\go\\src\\github.com\\FatimaAlmashhor\\fabric-samples\\asset-transfer-basic\\application-javascript\\node_modules\\fabric-network\\lib\\gateway.js',
    'D:\\fifthLevel\\blockchain\\hyperledger\\try-fabric-network\\go\\src\\github.com\\FatimaAlmashhor\\fabric-samples\\asset-transfer-basic\\application-javascript\\node_modules\\fabric-network\\index.js',
    'D:\\fifthLevel\\blockchain\\hyperledger\\try-fabric-network\\go\\src\\github.com\\FatimaAlmashhor\\fabric-samples\\asset-transfer-basic\\application-javascript\\app.js'
  ]
}

I do not know exactly from where the error is coming the node seems fine and all the packages I can see them inside the node_modules and package-lock.json

node -v
v16.3.0
npm -v
7.17.0
1 Answers

Looks like the fabric node-sdk has broken the feature where having a C compiler was optional, now it's mandatory but because pkcs11 is still declared as optional the node-sdk will not fail to install but will fail to run as you have seen. You are going to either have to

  1. install the microsoft C compilers + python v3 and re-install (or rebuild) the fabric node-sdk node module which will then be able to build the pkcs11 native library (see https://www.npmjs.com/package/windows-build-tools on how to install the compilers and python)
  2. specify a specific version of the fabric node sdk (It looks like it was broken in 2.2.4 so 2.2.3 should work) so erase the node_modules directory and update package.json to specify exactly the version of fabric-network (ie put in 2.2.3 with no preceding characters such as ^ or ~) and run npm install again
  3. Use a linux desktop distribution instead of windows as they tend to include the necessary pre-reqs to build a native node library

The final thing to note is that you are using a version of node and npm which aren't supported. You should use node 12 or node 14 as these are the lts releases supported

Related