fabric-samples icon indicating copy to clipboard operation
fabric-samples copied to clipboard

code: 'MODULE_NOT_FOUND', Error: Cannot find module '/usr/local/src/dist/index.js'

Open arturmartins opened this issue 8 months ago • 1 comments

Try to run hyperledger fabric 2.5.8 and try to follow along the https://hyperledger-fabric.readthedocs.io/en/latest/write_first_app.html

After successfully committed the chaincode:

2024-06-08 15:49:43.523 CDT 0001 INFO [chaincodeCmd] ClientWait -> txid [be4471845da588bdf5d82469f1675ceffe64c4a8d207d37a17af6658c79658ae] committed with status (VALID) at localhost:9051
2024-06-08 15:49:43.526 CDT 0002 INFO [chaincodeCmd] ClientWait -> txid [be4471845da588bdf5d82469f1675ceffe64c4a8d207d37a17af6658c79658ae] committed with status (VALID) at localhost:7051
Chaincode definition committed on channel 'mychannel'

I tried to run npm (node 18+ installed)

vagrant@vagrant:~/fabric-samples/asset-transfer-basic/application-gateway-typescript$ npm start

> [email protected] start
> node dist/app.js

channelName:       mychannel
chaincodeName:     basic
mspId:             Org1MSP
cryptoPath:        /home/vagrant/fabric-samples/test-network/organizations/peerOrganizations/org1.example.com
keyDirectoryPath:  /home/vagrant/fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/users/[email protected]/msp/keystore
certDirectoryPath: /home/vagrant/fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/users/[email protected]/msp/signcerts
tlsCertPath:       /home/vagrant/fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
peerEndpoint:      localhost:7051
peerHostAlias:     peer0.org1.example.com

--> Submit Transaction: InitLedger, function creates the initial set of assets on the ledger
******** FAILED to run the application: EndorseError: 10 ABORTED: failed to endorse transaction, see attached details for more info
    at /home/vagrant/fabric-samples/asset-transfer-basic/application-gateway-typescript/node_modules/@hyperledger/fabric-gateway/dist/client.js:36:251
    at Object.callback (/home/vagrant/fabric-samples/asset-transfer-basic/application-gateway-typescript/node_modules/@hyperledger/fabric-gateway/dist/client.js:93:27)
    at Object.onReceiveStatus (/home/vagrant/fabric-samples/asset-transfer-basic/application-gateway-typescript/node_modules/@grpc/grpc-js/build/src/client.js:193:36)
    at Object.onReceiveStatus (/home/vagrant/fabric-samples/asset-transfer-basic/application-gateway-typescript/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:360:141)
    ... 2 lines matching cause stack trace ...
    at process.processTicksAndRejections (node:internal/process/task_queues:77:11) {
  code: 10,
  details: [
    {
      address: 'peer0.org1.example.com:7051',
      message: 'error in simulation: failed to execute transaction 570a3fa3900c89fa9998556fa4aded8255ea7000774e899798e8bd2c71eba2b8: could not launch chaincode basic_1.0.1:f65cb9b3975454c9b1064a3b2f3fc9fc50366bd6e2d4a2c3170532f0d3759c78: chaincode registration failed: container exited with 1',
      mspId: 'Org1MSP'
    }
  ],
  cause: Error: 10 ABORTED: failed to endorse transaction, see attached details for more info
      at callErrorFromStatus (/home/vagrant/fabric-samples/asset-transfer-basic/application-gateway-typescript/node_modules/@grpc/grpc-js/build/src/call.js:31:19)
      at Object.onReceiveStatus (/home/vagrant/fabric-samples/asset-transfer-basic/application-gateway-typescript/node_modules/@grpc/grpc-js/build/src/client.js:193:76)
      at Object.onReceiveStatus (/home/vagrant/fabric-samples/asset-transfer-basic/application-gateway-typescript/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:360:141)
      at Object.onReceiveStatus (/home/vagrant/fabric-samples/asset-transfer-basic/application-gateway-typescript/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:323:181)
      at /home/vagrant/fabric-samples/asset-transfer-basic/application-gateway-typescript/node_modules/@grpc/grpc-js/build/src/resolving-call.js:129:78
      at process.processTicksAndRejections (node:internal/process/task_queues:77:11)
  for call at
      at Client.makeUnaryRequest (/home/vagrant/fabric-samples/asset-transfer-basic/application-gateway-typescript/node_modules/@grpc/grpc-js/build/src/client.js:161:32)
      at /home/vagrant/fabric-samples/asset-transfer-basic/application-gateway-typescript/node_modules/@hyperledger/fabric-gateway/dist/client.js:36:62
      at new Promise (<anonymous>)
      at GatewayClientImpl.endorse (/home/vagrant/fabric-samples/asset-transfer-basic/application-gateway-typescript/node_modules/@hyperledger/fabric-gateway/dist/client.js:36:16)
      at ProposalImpl.endorse (/home/vagrant/fabric-samples/asset-transfer-basic/application-gateway-typescript/node_modules/@hyperledger/fabric-gateway/dist/proposal.js:43:52)
      at async ContractImpl.submitAsync (/home/vagrant/fabric-samples/asset-transfer-basic/application-gateway-typescript/node_modules/@hyperledger/fabric-gateway/dist/contract.js:48:29)
      at async ContractImpl.submit (/home/vagrant/fabric-samples/asset-transfer-basic/application-gateway-typescript/node_modules/@hyperledger/fabric-gateway/dist/contract.js:40:27)
      at async initLedger (/home/vagrant/fabric-samples/asset-transfer-basic/application-gateway-typescript/dist/app.js:131:5)
      at async main (/home/vagrant/fabric-samples/asset-transfer-basic/application-gateway-typescript/dist/app.js:82:9) {
    code: 10,
    details: 'failed to endorse transaction, see attached details for more info',
    metadata: Metadata { internalRepr: [Map], options: {} }
  },
  transactionId: '570a3fa3900c89fa9998556fa4aded8255ea7000774e899798e8bd2c71eba2b8'
}
vagrant@vagrant:~/fabric-samples/asset-transfer-basic/application-gateway-typescript$

Investigating Searching for docker ps -a in order to get the node container ID

docker logs 1d9160f4339f

Output:

+ CHAINCODE_DIR=/usr/local/src
+ cd /usr/local/src
+ npm start -- --peer.address peer0.org1.example.com:7052

> [email protected] start
> set -x && fabric-chaincode-node start --peer.address peer0.org1.example.com:7052

+ fabric-chaincode-node start --peer.address peer0.org1.example.com:7052
fabric-chaincode-node start --peer.address localhost:7051 --chaincode-id-name mycc

Options:
      --help                                  Show help  [boolean]
  -v, --version                               Show version number  [boolean]
      --peer.address  [string] [required]
      --grpc.max_send_message_length  [number] [default: -1]
      --grpc.max_receive_message_length  [number] [default: -1]
      --grpc.keepalive_time_ms  [number] [default: 110000]
      --grpc.http2.min_time_between_pings_ms  [number] [default: 110000]
      --grpc.keepalive_timeout_ms  [number] [default: 20000]
      --grpc.http2.max_pings_without_data  [number] [default: 0]
      --grpc.keepalive_permit_without_calls  [number] [default: 1]
      --ssl-target-name-override  [string]
      --chaincode-id-name  [string] [required]
      --module-path  [string] [default: "/usr/local/src"]

Error: Cannot find module '/usr/local/src/dist/index.js'
Require stack:
- /usr/local/src/node_modules/fabric-shim/lib/contract-spi/bootstrap.js
- /usr/local/src/node_modules/fabric-shim/lib/cmds/metadata/lib/generate.js
- /usr/local/src/node_modules/fabric-shim/lib/cmds/metadata.js
- /usr/local/src/node_modules/yargs/index.cjs
- /usr/local/src/node_modules/fabric-shim/cli.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1145:15)
    at Module._load (node:internal/modules/cjs/loader:986:27)
    at Module.require (node:internal/modules/cjs/loader:1233:19)
    at require (node:internal/modules/helpers:179:18)
    at Bootstrap.getInfoFromContract (/usr/local/src/node_modules/fabric-shim/lib/contract-spi/bootstrap.js:77:23)
    at Bootstrap.bootstrap (/usr/local/src/node_modules/fabric-shim/lib/contract-spi/bootstrap.js:54:63)
    at exports.handler (/usr/local/src/node_modules/fabric-shim/lib/cmds/startCommand.js:38:21)
    at /usr/local/src/node_modules/yargs/build/index.cjs:1:8993
    at j (/usr/local/src/node_modules/yargs/build/index.cjs:1:4956)
    at _.handleValidationAndGetResult (/usr/local/src/node_modules/yargs/build/index.cjs:1:8962) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/usr/local/src/node_modules/fabric-shim/lib/contract-spi/bootstrap.js',
    '/usr/local/src/node_modules/fabric-shim/lib/cmds/metadata/lib/generate.js',
    '/usr/local/src/node_modules/fabric-shim/lib/cmds/metadata.js',
    '/usr/local/src/node_modules/yargs/index.cjs',
    '/usr/local/src/node_modules/fabric-shim/cli.js'
  ]
}

Indeed, there is no index.js

vagrant@vagrant:~/fabric-samples/asset-transfer-basic/application-gateway-typescript$ ls src dist
dist:
app.d.ts  app.js  app.js.map

src:
app.ts

Where is the problem located?

arturmartins avatar Jun 08 '24 21:06 arturmartins