Error while generating REST api using hyperledger

2019-08-12 08:46发布

I'm able to deploy business network using hyperledger composer in CentOS linux server but while generating REST apis using composer-rest-server i'm getting connection error?

[root@bctlpblockchain03 ~]#composer network ping -c admin@tutorial-network
The connection to the network was successfully tested: tutorial-network
        version: 0.15.2
        participant: org.hyperledger.composer.system.NetworkAdmin#admin

Command succeeded

[root@bctlpblockchain03 ~]# composer-rest-server
? Enter the name of the business network card to use: admin@tutorial-network
? Specify if you want namespaces in the generated REST API: never use namespaces


? Specify if you want to enable authentication for the REST API using Passport:
No
? Specify if you want to enable event publication over WebSockets: Yes
? Specify if you want to enable TLS security for the REST API: No

To restart the REST server using the same options, issue the following command:
   composer-rest-server -c admin@tutorial-network -n never -w true

Discovering types from business network definition ...
Connection fails: Error: Failed to load connector module "composer-connector-hlf                                                                                        v1" for connection type "hlfv1". Cannot find module '/root/.nvm/versions/node/v8                                                                                        .9.1/lib/node_modules/composer-rest-server/node_modules/grpc/src/node/extension_                                                                                        binary/node-v57-linux-x64/grpc_node.node'-Cannot find module '/root/.nvm/version                                                                                        s/node/v8.9.1/lib/node_modules/composer-rest-server/node_modules/grpc/src/node/e                                                                                        xtension_binary/node-v57-linux-x64/grpc_node.node'-Cannot find module '/root/.nv                                                                                        m/versions/node/v8.9.1/lib/node_modules/composer-rest-server/node_modules/grpc/s                                                                                        rc/node/extension_binary/node-v57-linux-x64/grpc_node.node'-Cannot find module '                                                                                        /root/.nvm/versions/node/v8.9.1/lib/node_modules/composer-rest-server/node_modul                                                                                        es/grpc/src/node/extension_binary/node-v57-linux-x64/grpc_node.node'-Cannot find                                                                                         module '/root/.nvm/versions/node/v8.9.1/lib/node_modules/composer-rest-server/n                                                                                        ode_modules/grpc/src/node/extension_binary/node-v57-linux-x64/grpc_node.node'-Ca                                                                                        nnot find module '/root/.nvm/versions/node/v8.9.1/lib/node_modules/composer-rest                                                                                        -server/node_modules/grpc/src/node/extension_binary/node-v57-linux-x64/grpc_node                                                                                        .node'-Cannot find module '/root/.nvm/versions/node/v8.9.1/lib/node_modules/comp                                                                                        oser-rest-server/node_modules/grpc/src/node/extension_binary/node-v57-linux-x64/                                                                                        grpc_node.node'-Cannot find module '/root/.nvm/versions/node/v8.9.1/lib/node_mod                                                                                        ules/composer-rest-server/node_modules/grpc/src/node/extension_binary/node-v57-l                                                                                        inux-x64/grpc_node.node'-Cannot find module '/root/.nvm/versions/node/v8.9.1/lib                                                                                        /node_modules/composer-rest-server/node_modules/grpc/src/node/extension_binary/n                                                                                        ode-v57-linux-x64/grpc_node.node'-Cannot find module '/root/.nvm/versions/node/v                                                                                        8.9.1/lib/node_modules/composer-rest-server/node_modules/grpc/src/node/extension                                                                                        _binary/node-v57-linux-x64/grpc_node.node'-Cannot find module '/root/.nvm/versio                                                                                        ns/node/v8.9.1/lib/node_modules/composer-rest-server/node_modules/grpc/src/node/                                                                                        extension_binary/node-v57-linux-x64/grpc_node.node'-Cannot find module '/root/.n                                                                                        vm/versions/node/v8.9.1/lib/node_modules/composer-rest-server/node_modules/grpc/                                                                                        src/node/extension_binary/node-v57-linux-x64/grpc_node.node'-Cannot find module                                                                                         '/root/.nvm/versions/node/v8.9.1/lib/node_modules/composer-rest-server/node_modu                                                                                        les/grpc/src/node/extension_binary/node-v57-linux-x64/grpc_node.node'-Cannot fin                                                                                        d module '/root/.nvm/versions/node/v8.9.1/lib/node_modules/composer-rest-server/                                                                                        node_modules/grpc/src/node/extension_binary/node-v57-linux-x64/grpc_node.node'
It will be retried for the next request.
Exception: Error: Failed to load connector module "composer-connector-hlfv1" for                                                                                         connection type "hlfv1". Cannot find module '/root/.nvm/versions/node/v8.9.1/li                                                                                        b/node_modules/composer-rest-server/node_modules/grpc/src/node/extension_binary/                                                                                        node-v57-linux-x64/grpc_node.node'-Cannot find module '/root/.nvm/versions/node/                                                                                        v8.9.1/lib/node_modules/composer-rest-server/node_modules/grpc/src/node/extensio                                                                                        n_binary/node-v57-linux-x64/grpc_node.node'-Cannot find module '/root/.nvm/versi                                                                                        ons/node/v8.9.1/lib/node_modules/composer-rest-server/node_modules/grpc/src/node                                                                                        /extension_binary/node-v57-linux-x64/grpc_node.node'-Cannot find module '/root/.                                                                                        nvm/versions/node/v8.9.1/lib/node_modules/composer-rest-server/node_modules/grpc                                                                                        /src/node/extension_binary/node-v57-linux-x64/grpc_node.node'-Cannot find module                                                                                         '/root/.nvm/versions/node/v8.9.1/lib/node_modules/composer-rest-server/node_mod                                                                                        ules/grpc/src/node/extension_binary/node-v57-linux-x64/grpc_node.node'-Cannot fi                                                                                        nd module '/root/.nvm/versions/node/v8.9.1/lib/node_modules/composer-rest-server                                                                                        /node_modules/grpc/src/node/extension_binary/node-v57-linux-x64/grpc_node.node'-                                                                                        Cannot find module '/root/.nvm/versions/node/v8.9.1/lib/node_modules/composer-re                                                                                        st-server/node_modules/grpc/src/node/extension_binary/node-v57-linux-x64/grpc_no                                                                                        de.node'-Cannot find module '/root/.nvm/versions/node/v8.9.1/lib/node_modules/co                                                                                        mposer-rest-server/node_modules/grpc/src/node/extension_binary/node-v57-linux-x6                                                                                        4/grpc_node.node'-Cannot find module '/root/.nvm/versions/node/v8.9.1/lib/node_m                                                                                        odules/composer-rest-server/node_modules/grpc/src/node/extension_binary/node-v57                                                                                        -linux-x64/grpc_node.node'-Cannot find module '/root/.nvm/versions/node/v8.9.1/l                                                                                        ib/node_modules/composer-rest-server/node_modules/grpc/src/node/extension_binary                                                                                        /node-v57-linux-x64/grpc_node.node'-Cannot find module '/root/.nvm/versions/node                                                                                        /v8.9.1/lib/node_modules/composer-rest-server/node_modules/grpc/src/node/extensi                                                                                        on_binary/node-v57-linux-x64/grpc_node.node'-Cannot find module '/root/.nvm/vers                                                                                        ions/node/v8.9.1/lib/node_modules/composer-rest-server/node_modules/grpc/src/nod                                                                                        e/extension_binary/node-v57-linux-x64/grpc_node.node'-Cannot find module '/root/                                                                                        .nvm/versions/node/v8.9.1/lib/node_modules/composer-rest-server/node_modules/grp                                                                                        c/src/node/extension_binary/node-v57-linux-x64/grpc_node.node'-Cannot find modul                                                                                        e '/root/.nvm/versions/node/v8.9.1/lib/node_modules/composer-rest-server/node_mo                                                                                        dules/grpc/src/node/extension_binary/node-v57-linux-x64/grpc_node.node'
Error: Failed to load connector module "composer-connector-hlfv1" for connection                                                                                         type "hlfv1". Cannot find module '/root/.nvm/versions/node/v8.9.1/lib/node_modu                                                                                        les/composer-rest-server/node_modules/grpc/src/node/extension_binary/node-v57-li                                                                                        nux-x64/grpc_node.node'-Cannot find module '/root/.nvm/versions/node/v8.9.1/lib/                                                                                        node_modules/composer-rest-server/node_modules/grpc/src/node/extension_binary/no                                                                                        de-v57-linux-x64/grpc_node.node'-Cannot find module '/root/.nvm/versions/node/v8                                                                                        .9.1/lib/node_modules/composer-rest-server/node_modules/grpc/src/node/extension_                                                                                        binary/node-v57-linux-x64/grpc_node.node'-Cannot find module '/root/.nvm/version                                                                                        s/node/v8.9.1/lib/node_modules/composer-rest-server/node_modules/grpc/src/node/e                                                                                        xtension_binary/node-v57-linux-x64/grpc_node.node'-Cannot find module '/root/.nv                                                                                        m/versions/node/v8.9.1/lib/node_modules/composer-rest-server/node_modules/grpc/s                                                                                        rc/node/extension_binary/node-v57-linux-x64/grpc_node.node'-Cannot find module '                                                                                        /root/.nvm/versions/node/v8.9.1/lib/node_modules/composer-rest-server/node_modul                                                                                        es/grpc/src/node/extension_binary/node-v57-linux-x64/grpc_node.node'-Cannot find                                                                                         module '/root/.nvm/versions/node/v8.9.1/lib/node_modules/composer-rest-server/n                                                                                        ode_modules/grpc/src/node/extension_binary/node-v57-linux-x64/grpc_node.node'-Ca                                                                                        nnot find module '/root/.nvm/versions/node/v8.9.1/lib/node_modules/composer-rest                                                                                        -server/node_modules/grpc/src/node/extension_binary/node-v57-linux-x64/grpc_node                                                                                        .node'-Cannot find module '/root/.nvm/versions/node/v8.9.1/lib/node_modules/comp                                                                                        oser-rest-server/node_modules/grpc/src/node/extension_binary/node-v57-linux-x64/                                                                                        grpc_node.node'-Cannot find module '/root/.nvm/versions/node/v8.9.1/lib/node_mod                                                                                        ules/composer-rest-server/node_modules/grpc/src/node/extension_binary/node-v57-l                                                                                        inux-x64/grpc_node.node'-Cannot find module '/root/.nvm/versions/node/v8.9.1/lib                                                                                        /node_modules/composer-rest-server/node_modules/grpc/src/node/extension_binary/n                                                                                        ode-v57-linux-x64/grpc_node.node'-Cannot find module '/root/.nvm/versions/node/v                                                                                        8.9.1/lib/node_modules/composer-rest-server/node_modules/grpc/src/node/extension                                                                                        _binary/node-v57-linux-x64/grpc_node.node'-Cannot find module '/root/.nvm/versio                                                                                        ns/node/v8.9.1/lib/node_modules/composer-rest-server/node_modules/grpc/src/node/                                                                                        extension_binary/node-v57-linux-x64/grpc_node.node'-Cannot find module '/root/.n                                                                                        vm/versions/node/v8.9.1/lib/node_modules/composer-rest-server/node_modules/grpc/                                                                                        src/node/extension_binary/node-v57-linux-x64/grpc_node.node'
    at Promise.resolve.then (/root/.nvm/versions/node/v8.9.1/lib/node_modules/co                                                                                        mposer-rest-server/node_modules/composer-common/lib/connectionprofilemanager.js:                                                                                        136:42)
    at <anonymous>

4条回答
虎瘦雄心在
2楼-- · 2019-08-12 09:12

you need to rebuild it

go to the folder first

cd '/root/.nvm/versi ons/node/v8.9.1/lib/node_modules/composer-rest-server/'

(into the folder where you have 'composer-rest-server')

then

npm rebuild --unsafe-prem

It will work now

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-08-12 09:13

When I tried the command:

npm rebuild --unsafe-prem

It threw me an error saying Warning "root" does not have permission to access the dev dir.

I just added sudo and it worked well for me!:

sudo npm rebuild --unsafe-prem

查看更多
放我归山
4楼-- · 2019-08-12 09:13

All the above solution works fine, but they are temporary fixed. I had the same problem and I used the sudo npm rebuild --unsafe-prem solution. The problem did go away for a while, but I kept running into it again and again.

I read the documentation again @ https://hyperledger.github.io/composer/latest/installing/installing-prereqs.

**If installing Hyperledger Composer using Linux, be aware of the following advice:

Login as a normal user, rather than root.

Do not su to root.

When installing prerequisites, use curl, then unzip using sudo.

Run prereqs-ubuntu.sh as a normal user. It may prompt for root password as some of it's actions are required to be run as root.

Do not use npm with sudo or su to root to use it.

Avoid installing node globally as root.**

Doing this will really help you in long run, Goodluck !

查看更多
劳资没心,怎么记你
5楼-- · 2019-08-12 09:26

In my case the problem was "node-v57-linux-x64" I had "node-v59-linux-x64" and I solved it in the following way:

cd /usr/lib/node_modules/composer-rest-server/node_modules/

then

npm rebuild --unsafe-prem

It worked for me the two times I had the error

查看更多
登录 后发表回答