Search code examples
node.jsmodulehyperledgerinstantiationchaincode

Cannot find module ledger-api/state.js on chaincode instantiation


I'm trying to instantiate a chaincode after I installed it succesfully with the following command docker container exec -it cli peer chaincode install -n mycontract p /opt/gopath/src/github.com/sacc -v 1.0 -l node and when I try to instantiate it with this command docker container exec -it cli peer chaincode instantiate -n mycontract -v 1.0 -o orderer.example.com:7050 -C mychannel -c '{"Args":["org.myproject.com:instantiate"]}' -P "AND('Org1MSP.member')" -l node I'm getting these erros messages on my peer logs

UTC [peer.chaincode.dev-peer0.org1.example.com-mycontract-1.0] func2 -> INFO 077 Error: Cannot find module './../ledger-api/state.js'

UTC [peer.chaincode.dev-peer0.org1.example.com-mycontract-1.0] func2 -> INFO 078 at Function.Module._resolveFilename (module.js:548:15)

UTC [peer.chaincode.dev-peer0.org1.example.com-mycontract-1.0] func2 -> INFO 079 at Function.Module._load (module.js:475:25)

UTC [peer.chaincode.dev-peer0.org1.example.com-mycontract-1.0] func2 -> INFO 07a at Module.require (module.js:597:17)

UTC [peer.chaincode.dev-peer0.org1.example.com-mycontract-1.0] func2 -> INFO 07b at require (internal/module.js:11:18)

UTC [peer.chaincode.dev-peer0.org1.example.com-mycontract-1.0] func2 -> INFO 07c at Object. (/usr/local/src/documentototal.js:17:15)

UTC [peer.chaincode.dev-peer0.org1.example.com-mycontract-1.0] func2 -> INFO 07d at Module._compile (module.js:653:30)

UTC [peer.chaincode.dev-peer0.org1.example.com-mycontract-1.0] func2 -> INFO 07e at Object.Module._extensions..js (module.js:664:10)

UTC [peer.chaincode.dev-peer0.org1.example.com-mycontract-1.0] func2 -> INFO 07f at Module.load (module.js:566:32)

UTC [peer.chaincode.dev-peer0.org1.example.com-mycontract-1.0] func2 -> INFO 080 at tryModuleLoad (module.js:506:12)

UTC [peer.chaincode.dev-peer0.org1.example.com-mycontract-1.0] func2 -> INFO 081 at Function.Module._load (module.js:498:3)

What is causing this error?


Solution

  • It was a silly mistake. When we instantiate a chaincode we are creating a docker image for that specific chaincode, with the specfic name and version we give to it. Even if we make changes in it, that same image will always be used if we try to instantiate it using the same command. So if you are facing similar problems with chaincode instantiation I would adivise you run docker image rmi $(docker image images dev-* -q) and then try to instantiate your chaincode again. Hope this helps someone else.