Search code examples
node.jsnpmbitcoinnvmbitcore

Node App Cannot Find Global Module Bitcore


I've installed bitcore (https://github.com/bitpay/bitcore) using "npm install -g bitcore" with NVM running node v4.8.2, confirmed with "node -v" and "which node".

The CLI works, and I am able to run my full node as a service (using pm2).

However, I want to use bitcore-lib in my app, which I have added to my dependencies. In my code I have a little test to make sure I have my modules working, which looks like this:

var bitcore = require('bitcore');
...
var privateKey = new bitcore.PrivateKey();
var address = privateKey.toAddress();
...

All of this is good, but when I try to build the app is fails with:

Error: Cannot find module 'bitcore'

I checked my global libraries in my nvm directory at ~/.nvm/versions/node/v4.8.2/lib/node_modules and sure enough bitcore is present.

Why would "node server.js" be unable to find the module if it is available globally to the same version of node in NVM?


Solution

  • Global modules are not requireable - global installs are only for command line tools.

    If you require it, it's a dependency - so it needs to be locally installed and in your app's package.json.