9

After installing Hyperledger Composer cli from this page, I tried to call composer command but got this error:

module.js:549
throw err;
^

Error: Cannot find module './api'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/home/user/.nvm/versions/node/v8.11.1/lib/node_modules/composer-cli/node_modules/node-report/index.js:3:13)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)

I used this command to install Hyperledger Composer:

npm install --unsafe-perm -g composer-cli

May I know what is going wrong?

AshT
  • 535
  • 1
  • 8
  • 20

3 Answers3

18

In my case I installed composer-cli in global /usr/lib/node_modules/composer-cli and I met the same problem. I don't know what's wrong but I tried:

  1. Change directory into the composer-cli:

    cd /usr/lib/node_modules/composer-cli

  2. Reinstall node report module, locally inside the composer-cli:

    sudo npm install node-report --unsafe-perm

Notice I don't put -g param in sudo npm install to make the installation local to the composer-cli itself.

The node-report will run make with g++ to compile something (which for some reason was not run during composer-cli installation) and it just works... Now I can run composer.

For your case set the working directory to /home/user/.nvm/versions/node/v8.11.1/lib/node_modules/composer-cli instead.

Christian Lim
  • 369
  • 4
  • 14
7

The answer is

1) DON'T resort to using root or sudo (as advised in a comment above) to install Composer npm modules - this causes issues for npm per the prerequisites . Instead, follow best practices for npm installs: don't use sudo or root to install Composer - it will always cause issues further down the line. Follow the best practices here https://docs.npmjs.com/getting-started/fixing-npm-permissions

2) Have a supported npm version (5.x as of June 2018) per the install docs

3) Install - then use - nvm to manage your NODE versions - as indicated above Node 8.11.x is supported. For NVM - see https://github.com/creationix/nvm#installation - it installs it. Eg. nvm install v8.11.1 2) nvm use 8.11.1 etc

4) If you have already / previously installed Composer modules using sudo or root - remove them using that id using npm uninstall -g (ie global), then follow the 'best practices' mentioned above in 1) and follow the Composer install docs to do the Composer modules install - very very straightfoward.

Following these steps - it works every time.

Paul O'Mahony
  • 6,740
  • 1
  • 10
  • 15
2

For me, completely wiping

rm -rf /usr/lib/node_modules/composer-cli

and executing npm install -g composer-cli

did the job :) (reinstalling node-report didnt work)

BiS
  • 501
  • 4
  • 17
  • Notice the debug (from the question) `at Object. (/home/user/.nvm/versions/node/v8.11.1/lib/node_modules/composer-cli/node_modules/node-report/index.js:3:13)` which is why my answer was about `node-report` as well. Maybe in your case it was not node-report. – Christian Lim May 02 '18 at 03:28
  • it was node-report in the debug, No idea why the reinstall didn't work – BiS May 03 '18 at 15:25