bitcore icon indicating copy to clipboard operation
bitcore copied to clipboard

Error: More than one instance of bitcore-lib found.

Open Johannbr opened this issue 8 years ago • 23 comments

Hi I'm trying to install a full node (https://bitcore.io/guides/full-node/), but I ran into this error: Error: More than one instance of bitcore-lib found. Please make sure to require bitcore-lib and check that submodules do not also include their own bitcore-lib depen

Previous environment:

node 6 and npm 3

Steps: 1- npm install -g bitcore => got an error 2- sudo npm install -g bitcore 3- sudo apt-get install libzmq3-dev build-essential Then I read that you should not install it with root privileges 4- Remove npm and node from my system (even cache and tmp folder) 5- install nvm with node 4.8.3 and npm 2.15.11

Current environment:

nvm with node 4.8.3 and npm 2.15.11

Steps: 1- npm install -g bitcore 2- bitcored => Error: More than one instance of bitcore-lib found.

I don't know how to make it work. If you have any ideas ;-)

Log: /home/johann/.nvm/versions/node/v4.8.3/lib/node_modules/bitcore/node_modules/insight-api/node_modules/bitcore-lib/index.js:12 throw new Error(message); ^

Error: More than one instance of bitcore-lib found. Please make sure to require bitcore-lib and check that submodules do not also include their own bitcore-lib dependency. at Object.bitcore.versionGuard (/home/johann/.nvm/versions/node/v4.8.3/lib/node_modules/bitcore/node_modules/insight-api/node_modules/bitcore-lib/index.js:12:11) at Object. (/home/johann/.nvm/versions/node/v4.8.3/lib/node_modules/bitcore/node_modules/insight-api/node_modules/bitcore-lib/index.js:15:9) at Module._compile (module.js:409:26) at Object.Module._extensions..js (module.js:416:10) at Module.load (module.js:343:32) at Function.Module._load (module.js:300:12) at Module.require (module.js:353:17) at require (internal/module.js:12:17) at Object. (/home/johann/.nvm/versions/node/v4.8.3/lib/node_modules/bitcore/node_modules/insight-api/lib/blocks.js:4:15) at Module._compile (module.js:409:26)

Johannbr avatar Jun 20 '17 11:06 Johannbr

@Johannbr Same issue for me. I had some struggles trying to install bitcore due to a permission error. Eventually I installed it. I went back and deleted the global and project level installations and bitcore, but still get the same error as above. I also went and manually deleted the bitcore packages from the global npm directory, but no joy.

raymondcarl avatar Jul 09 '17 11:07 raymondcarl

Hi, I found a solution here: Issue 1454

Well, this is far from a proper way to solve this issue, but you can get rid of this error by editing file

~/.nvm/versions/node/v4.8.3/lib/node_modules/bitcore/node_modules/insight-api/node_modules/bitcore-lib/index.js

line 7: bitcore.versionGuard = function(version) { Change it to: bitcore.versionGuard = function(version) { return;

Johannbr avatar Jul 10 '17 09:07 Johannbr

I had the exactly same trouble, and fixed by the exactly same workaround. not sure should I send a PR, though.

joemphilips avatar Jul 18 '17 14:07 joemphilips

Worked for me too, after spending a day on it :(

bitcoinbrisbane avatar Jul 19 '17 06:07 bitcoinbrisbane

It works, as long as you make the same correction to *all your instances of bitcore-lib/index.js

Fatima-yo avatar Aug 06 '17 04:08 Fatima-yo

Same problem, same solution. Thanx, @Johannbr !

AlexanderKozhevin avatar Aug 16 '17 07:08 AlexanderKozhevin

newer versions are broken, see comments here: https://github.com/bitpay/bitcore/commit/ad4e25ef1b562163c398518079e796f9f704afe6

pira avatar Nov 08 '17 06:11 pira

Same problem here. How did you guys fix it? There is no file: ~/.nvm/versions/node/v4.8.7/lib/node_modules/bitcore/node_modules/insight-api/node_modules/bitcore-lib/index.js

usab avatar Dec 12 '17 14:12 usab

I just opened node_modules/bitcore-mnemoic/node_modules/bitcore-lib/index.js and commented out the following lines of code

bitcore.versionGuard = function(version) {
  // if (version !== undefined) {
  //   var message = 'More than one instance of bitcore-lib found. ' +
  //     'Please make sure to require bitcore-lib and check that submodules do' +
  //     ' not also include their own bitcore-lib dependency.';
  //   throw new Error(message);
  // }
};

ltfschoen avatar Dec 16 '17 21:12 ltfschoen

The solution that @Johannbr suggested worked. If you have multiple bitcore libraries you need to return all the bitcore.versionGuard conditions

tinkerNamedFerro avatar Jun 28 '18 02:06 tinkerNamedFerro

try adding "postinstall": "find ./node_modules/**/node_modules -type d -name 'bitcore-lib' -exec rm -r {} + && echo 'Deleted duplicate bitcore-libs'" to your package.json. curtsey of @Tahseenm

Neats29 avatar Jan 17 '19 10:01 Neats29

I have found a full proof solution to this :+1:

Object.defineProperty(global, '_bitcore', { get(){ return undefined }, set(){} })

enjoy !!

adiingit avatar Feb 26 '19 20:02 adiingit

@adiingit are you putting that in the versionguard function?

silence48 avatar Mar 03 '19 19:03 silence48

@adiingit Great!

Any chance you could make a pull request with the change?

mathiasrw avatar Apr 03 '19 00:04 mathiasrw

@silence48 : no , not in version gaurd function . Put it as the init of your application or app.js .

adiingit avatar Apr 03 '19 01:04 adiingit

@adiingit thanks I figured it out shortly after appreciate the fix

silence48 avatar Apr 03 '19 02:04 silence48

@mathiasrw : do we need a PR to bitcore lib for this ? We can add this to our app instead .

adiingit avatar Apr 03 '19 03:04 adiingit

I think I found a very Good work Around with version control or editing the code in your node modules because to me that is a bad practice

var p2p     = require('bitcore-p2p');                           //p2p exports
var p2pMod  = require.cache[require.resolve('bitcore-p2p')];    //p2p module
var bitcore = p2pMod.require('bitcore-lib');   

Or

var p2p     = require('bitcore-p2p');                           //p2p exports    
var bitcore = require('bitcore-p2p/node_modules/bitcore-lib');  //p2p/bitcore-lib exports

https://stackoverflow.com/a/53814090/2618449

dagogodboss avatar May 17 '19 13:05 dagogodboss

@dagogodboss what if you don't want to use Bitcore-p2p ? I just want lib and explorers

morenoh149 avatar Oct 12 '19 07:10 morenoh149

Object.defineProperty(global, '_bitcore', { get(){ return undefined }, set(){} })

Where do I add that line?

Gabo1122 avatar Nov 29 '19 13:11 Gabo1122

I have found a full proof solution to this 👍

Object.defineProperty(global, '_bitcore', { get(){ return undefined }, set(){} })

enjoy !!

@adiingit's works great 👍

but if you're using bitcore-lib-cash, you have to change it to:

Object.defineProperty(global, '_bitcoreCash', { get(){ return undefined }, set(){} })

nyusternie avatar Jun 26 '20 17:06 nyusternie

fyi, last I looked into these things I found https://bcoin.io as a higher quality bitcoin javascript library

morenoh149 avatar Jun 29 '20 14:06 morenoh149

Hi, I found a solution here: Issue 1454

Well, this is far from a proper way to solve this issue, but you can get rid of this error by editing file ~/.nvm/versions/node/v4.8.3/lib/node_modules/bitcore/node_modules/insight-api/node_modules/bitcore-lib/index.js line 7: bitcore.versionGuard = function(version) { Change it to: bitcore.versionGuard = function(version) { return;

Resolved

ink-web3 avatar Jan 03 '23 03:01 ink-web3